Mercurial > minori
comparison src/gui/window.cc @ 236:4d461ef7d424
HUGE UPDATE: convert build system to autotools
why? because cmake sucks :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 19 Jan 2024 00:24:02 -0500 |
parents | ff0061e75f0f |
children | a7d0d543b334 |
comparison
equal
deleted
inserted
replaced
235:593108b3d555 | 236:4d461ef7d424 |
---|---|
91 for (const auto& file : files) { | 91 for (const auto& file : files) { |
92 anitomy::Anitomy anitomy; | 92 anitomy::Anitomy anitomy; |
93 anitomy.Parse(Strings::ToWstring(file)); | 93 anitomy.Parse(Strings::ToWstring(file)); |
94 | 94 |
95 const auto& elements = anitomy.elements(); | 95 const auto& elements = anitomy.elements(); |
96 | 96 const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); |
97 int id = Anime::db.GetAnimeFromTitle(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle))); | 97 std::cout << title << std::endl; |
98 | |
99 int id = Anime::db.GetAnimeFromTitle(title); | |
98 if (id <= 0) | 100 if (id <= 0) |
99 continue; | 101 continue; |
100 | 102 |
101 page->SetPlaying(Anime::db.items[id], elements); | 103 page->SetPlaying(Anime::db.items[id], elements); |
102 break; | 104 break; |
158 } | 160 } |
159 | 161 |
160 void MainWindow::CreateBars() { | 162 void MainWindow::CreateBars() { |
161 QMenuBar* menubar = new QMenuBar(this); | 163 QMenuBar* menubar = new QMenuBar(this); |
162 QMenu* folder_menu; /* this is used twice, so we declare it here */ | 164 QMenu* folder_menu; /* this is used twice, so we declare it here */ |
165 QAction* sync_action; | |
163 | 166 |
164 { | 167 { |
165 /* File */ | 168 /* File */ |
166 QMenu* menu = menubar->addMenu(tr("&File")); | 169 QMenu* menu = menubar->addMenu(tr("&File")); |
167 | 170 |
229 { | 232 { |
230 /* Services */ | 233 /* Services */ |
231 QMenu* menu = menubar->addMenu(tr("&Services")); | 234 QMenu* menu = menubar->addMenu(tr("&Services")); |
232 { | 235 { |
233 { | 236 { |
234 QAction* action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack.get()); }); | 237 sync_action = menu->addAction(tr("Synchronize &list")); |
235 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); | 238 |
239 connect(sync_action, &QAction::triggered, this, [this, sync_action]{ | |
240 AsyncSynchronize(sync_action, stack.get()); | |
241 }); | |
242 | |
243 sync_action->setIcon(QIcon(":/icons/24x24/arrow-circle-double-135.png")); | |
244 sync_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); | |
236 } | 245 } |
237 | 246 |
238 // menu->addSeparator(); | 247 // menu->addSeparator(); |
239 // | 248 // |
240 // { | 249 // { |
298 | 307 |
299 { | 308 { |
300 QAction* action = menu->addAction(tr("&Settings"), [this] { | 309 QAction* action = menu->addAction(tr("&Settings"), [this] { |
301 SettingsDialog dialog(this); | 310 SettingsDialog dialog(this); |
302 dialog.exec(); | 311 dialog.exec(); |
312 CreateBars(); | |
303 }); | 313 }); |
304 action->setMenuRole(QAction::PreferencesRole); | 314 action->setMenuRole(QAction::PreferencesRole); |
305 } | 315 } |
306 } | 316 } |
307 | 317 |
406 } | 416 } |
407 | 417 |
408 { | 418 { |
409 /* Toolbar */ | 419 /* Toolbar */ |
410 QToolBar* toolbar = new QToolBar(this); | 420 QToolBar* toolbar = new QToolBar(this); |
411 toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), | 421 toolbar->addAction(sync_action); |
412 [this] { AsyncSynchronize(stack.get()); }); | |
413 | 422 |
414 toolbar->addSeparator(); | 423 toolbar->addSeparator(); |
415 | 424 |
416 { | 425 { |
417 QToolButton* button = new QToolButton(toolbar); | 426 QToolButton* button = new QToolButton(toolbar); |
463 | 472 |
464 toolbar->addSeparator(); | 473 toolbar->addSeparator(); |
465 toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { | 474 toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { |
466 SettingsDialog dialog(this); | 475 SettingsDialog dialog(this); |
467 dialog.exec(); | 476 dialog.exec(); |
477 CreateBars(); | |
468 }); | 478 }); |
469 addToolBar(toolbar); | 479 addToolBar(toolbar); |
470 } | 480 } |
471 } | 481 } |
472 | 482 |
473 void MainWindow::SetActivePage(QWidget* page) { | 483 void MainWindow::SetActivePage(QWidget* page) { |
474 this->setCentralWidget(page); | 484 this->setCentralWidget(page); |
475 } | 485 } |
476 | 486 |
477 void MainWindow::AsyncSynchronize(QStackedWidget* stack) { | 487 void MainWindow::AsyncSynchronize(QAction* action, QStackedWidget* stack) { |
478 if (session.config.service == Anime::Services::NONE) { | 488 if (session.config.service == Anime::Services::NONE) { |
479 QMessageBox msg; | 489 QMessageBox msg; |
480 msg.setWindowTitle(tr("Error synchronizing with service!")); | 490 msg.setWindowTitle(tr("Error synchronizing with service!")); |
481 msg.setText(tr("It seems you haven't yet selected a service to use.")); | 491 msg.setText(tr("It seems you haven't yet selected a service to use.")); |
482 msg.setInformativeText(tr("Would you like to select one now?")); | 492 msg.setInformativeText(tr("Would you like to select one now?")); |
486 if (ret == QMessageBox::Yes) { | 496 if (ret == QMessageBox::Yes) { |
487 SettingsDialog dialog; | 497 SettingsDialog dialog; |
488 dialog.exec(); | 498 dialog.exec(); |
489 } | 499 } |
490 } | 500 } |
491 QThreadPool::globalInstance()->start([stack] { | 501 |
502 QThreadPool::globalInstance()->start([stack, action] { | |
503 action->setEnabled(false); | |
492 Services::Synchronize(); | 504 Services::Synchronize(); |
493 reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh(); | 505 reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh(); |
506 action->setEnabled(true); | |
494 }); | 507 }); |
495 } | 508 } |
496 | 509 |
497 void MainWindow::RetranslateUI() { | 510 void MainWindow::RetranslateUI() { |
498 /* This kinda sucks but nobody's really going to be changing | 511 /* This kinda sucks but nobody's really going to be changing |
532 void MainWindow::closeEvent(QCloseEvent* event) { | 545 void MainWindow::closeEvent(QCloseEvent* event) { |
533 session.config.Save(); | 546 session.config.Save(); |
534 Anime::db.SaveDatabaseToDisk(); | 547 Anime::db.SaveDatabaseToDisk(); |
535 event->accept(); | 548 event->accept(); |
536 } | 549 } |
537 | |
538 #include "gui/moc_window.cpp" |