Mercurial > minori
comparison src/gui/window.cc @ 114:ab191e28e69d
*: add initial torrent stuff
WOAH!
these checkboxes are a pain in my fucking ass
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Tue, 07 Nov 2023 08:03:42 -0500 |
| parents | 32afe0e940bf |
| children | c72b907b9bef |
comparison
equal
deleted
inserted
replaced
| 113:32afe0e940bf | 114:ab191e28e69d |
|---|---|
| 51 }; | 51 }; |
| 52 | 52 |
| 53 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { | 53 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
| 54 setWindowIcon(QIcon(":/favicon.png")); | 54 setWindowIcon(QIcon(":/favicon.png")); |
| 55 | 55 |
| 56 main_widget = new QWidget(this); | 56 main_widget.reset(new QWidget(this)); |
| 57 /*QHBoxLayout* layout = */new QHBoxLayout(main_widget); | 57 /*QHBoxLayout* layout = */new QHBoxLayout(main_widget.get()); |
| 58 | 58 |
| 59 AddMainWidgets(); | 59 AddMainWidgets(); |
| 60 | 60 |
| 61 setCentralWidget(main_widget); | 61 setCentralWidget(main_widget.get()); |
| 62 | 62 |
| 63 CreateBars(); | 63 CreateBars(); |
| 64 | 64 |
| 65 QTimer* timer = new QTimer(this); | 65 QTimer* timer = new QTimer(this); |
| 66 connect(timer, &QTimer::timeout, this, [this] { | 66 connect(timer, &QTimer::timeout, this, [this] { |
| 79 timer->start(5000); | 79 timer->start(5000); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void MainWindow::AddMainWidgets() { | 82 void MainWindow::AddMainWidgets() { |
| 83 int page = static_cast<int>(Pages::ANIME_LIST); | 83 int page = static_cast<int>(Pages::ANIME_LIST); |
| 84 if (sidebar) { | 84 if (sidebar.get()) { |
| 85 main_widget->layout()->removeWidget(sidebar); | 85 main_widget->layout()->removeWidget(sidebar.get()); |
| 86 delete sidebar; | 86 sidebar.reset(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 if (stack) { | 89 if (stack.get()) { |
| 90 page = stack->currentIndex(); | 90 page = stack->currentIndex(); |
| 91 main_widget->layout()->removeWidget(stack); | 91 main_widget->layout()->removeWidget(stack.get()); |
| 92 delete stack; | 92 } |
| 93 } | 93 |
| 94 | 94 sidebar.reset(new SideBar(main_widget.get())); |
| 95 sidebar = new SideBar(main_widget); | |
| 96 sidebar->setFixedWidth(128); | 95 sidebar->setFixedWidth(128); |
| 97 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | 96 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
| 98 | 97 |
| 99 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); | 98 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
| 100 sidebar->AddSeparator(); | 99 sidebar->AddSeparator(); |
| 104 sidebar->AddSeparator(); | 103 sidebar->AddSeparator(); |
| 105 sidebar->AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); | 104 sidebar->AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
| 106 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); | 105 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); |
| 107 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); | 106 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); |
| 108 | 107 |
| 109 stack = new QStackedWidget(main_widget); | 108 stack.reset(new QStackedWidget(main_widget.get())); |
| 110 stack->addWidget(new NowPlayingPage(main_widget)); | 109 stack->addWidget(new NowPlayingPage(main_widget.get())); |
| 111 stack->addWidget(new AnimeListPage(main_widget)); | 110 stack->addWidget(new AnimeListPage(main_widget.get())); |
| 112 stack->addWidget(new HistoryPage(main_widget)); | 111 stack->addWidget(new HistoryPage(main_widget.get())); |
| 113 stack->addWidget(new StatisticsPage(main_widget)); | 112 stack->addWidget(new StatisticsPage(main_widget.get())); |
| 114 stack->addWidget(new SearchPage(main_widget)); | 113 stack->addWidget(new SearchPage(main_widget.get())); |
| 115 stack->addWidget(new SeasonsPage(main_widget)); | 114 stack->addWidget(new SeasonsPage(main_widget.get())); |
| 116 stack->addWidget(new TorrentsPage(main_widget)); | 115 stack->addWidget(new TorrentsPage(main_widget.get())); |
| 117 | 116 |
| 118 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); | 117 connect(sidebar.get(), &SideBar::CurrentItemChanged, stack.get(), &QStackedWidget::setCurrentIndex); |
| 119 sidebar->SetCurrentItem(page); | 118 sidebar->SetCurrentItem(page); |
| 120 | 119 |
| 121 main_widget->layout()->addWidget(sidebar); | 120 main_widget->layout()->addWidget(sidebar.get()); |
| 122 main_widget->layout()->addWidget(stack); | 121 main_widget->layout()->addWidget(stack.get()); |
| 123 } | 122 } |
| 124 | 123 |
| 125 void MainWindow::CreateBars() { | 124 void MainWindow::CreateBars() { |
| 126 /* Menu Bar */ | 125 /* Menu Bar |
| 127 QAction* action; | 126 The notation of these might seem ugly at first, but it's actually very nice |
| 127 (just trust me). It makes it much easier to edit the lists and makes it clear | |
| 128 if you're in submenu or not. */ | |
| 128 QMenuBar* menubar = new QMenuBar(this); | 129 QMenuBar* menubar = new QMenuBar(this); |
| 129 QMenu* menu = menubar->addMenu(tr("&File")); | 130 |
| 130 | 131 { |
| 131 QMenu* submenu = menu->addMenu(tr("&Library folders")); | 132 /* File */ |
| 132 action = submenu->addAction(tr("&Add new folder...")); | 133 QMenu* menu = menubar->addMenu(tr("&File")); |
| 133 | 134 |
| 134 action = menu->addAction(tr("&Scan available episodes")); | 135 { |
| 135 | 136 QMenu* submenu = menu->addMenu(tr("&Library folders")); |
| 136 menu->addSeparator(); | 137 { |
| 137 | 138 QAction* action = submenu->addAction(tr("&Add new folder...")); |
| 138 action = menu->addAction(tr("Play &next episode")); | 139 } |
| 139 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); | 140 } |
| 140 action = menu->addAction(tr("Play &random episode")); | 141 |
| 141 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); | 142 { |
| 142 | 143 QAction* action = menu->addAction(tr("&Scan available episodes")); |
| 143 menu->addSeparator(); | 144 } |
| 144 | 145 |
| 145 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); | 146 menu->addSeparator(); |
| 146 | 147 |
| 147 menu = menubar->addMenu(tr("&Services")); | 148 // { |
| 148 action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack); }); | 149 // QAction* action = menu->addAction(tr("Play &next episode")); |
| 149 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); | 150 // action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); |
| 150 | 151 // } |
| 151 menu->addSeparator(); | 152 // |
| 152 | 153 // { |
| 153 submenu = menu->addMenu(tr("&AniList")); | 154 // QAction* action = menu->addAction(tr("Play &random episode")); |
| 154 action = submenu->addAction(tr("Go to my &profile")); | 155 // action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); |
| 155 action = submenu->addAction(tr("Go to my &stats")); | 156 // } |
| 156 | 157 |
| 157 submenu = menu->addMenu(tr("&Kitsu")); | 158 menu->addSeparator(); |
| 158 action = submenu->addAction(tr("Go to my &feed")); | 159 |
| 159 action = submenu->addAction(tr("Go to my &library")); | 160 { |
| 160 action = submenu->addAction(tr("Go to my &profile")); | 161 QAction* action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); |
| 161 | 162 } |
| 162 submenu = menu->addMenu(tr("&MyAnimeList")); | 163 } |
| 163 action = submenu->addAction(tr("Go to my p&anel")); | 164 |
| 164 action = submenu->addAction(tr("Go to my &profile")); | 165 { |
| 165 action = submenu->addAction(tr("Go to my &history")); | 166 /* Services */ |
| 166 | 167 QMenu* menu = menubar->addMenu(tr("&Services")); |
| 167 menu = menubar->addMenu(tr("&Tools")); | 168 { |
| 168 submenu = menu->addMenu(tr("&Export anime list")); | 169 { |
| 169 action = submenu->addAction(tr("Export as &Markdown...")); | 170 QAction* action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack.get()); }); |
| 170 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | 171 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); |
| 171 | 172 } |
| 172 menu->addSeparator(); | 173 |
| 173 | 174 // menu->addSeparator(); |
| 174 action = menu->addAction(tr("Enable anime &recognition")); | 175 // |
| 175 action->setCheckable(true); | 176 // { |
| 176 action = menu->addAction(tr("Enable auto &sharing")); | 177 // /* AniList */ |
| 177 action->setCheckable(true); | 178 // QMenu* submenu = menu->addMenu(tr("&AniList")); |
| 178 action = menu->addAction(tr("Enable &auto synchronization")); | 179 // QAction* action = submenu->addAction(tr("Go to my &profile")); |
| 179 action->setCheckable(true); | 180 // action = submenu->addAction(tr("Go to my &stats")); |
| 180 | 181 // } |
| 181 menu->addSeparator(); | 182 // |
| 182 | 183 // { |
| 183 action = menu->addAction(tr("&Settings"), [this] { | 184 // /* Kitsu */ |
| 184 SettingsDialog dialog(this); | 185 // QMenu* submenu = menu->addMenu(tr("&Kitsu")); |
| 185 dialog.exec(); | 186 // QAction* action = submenu->addAction(tr("Go to my &feed")); |
| 186 }); | 187 // action = submenu->addAction(tr("Go to my &library")); |
| 187 action->setMenuRole(QAction::PreferencesRole); | 188 // action = submenu->addAction(tr("Go to my &profile")); |
| 188 | 189 // } |
| 189 menu = menubar->addMenu(tr("&View")); | 190 // { |
| 190 | 191 // QMenu* submenu = menu->addMenu(tr("&MyAnimeList")); |
| 191 std::map<QAction*, int> page_to_index_map = {}; | 192 // QAction* action = submenu->addAction(tr("Go to my p&anel")); |
| 192 | 193 // action = submenu->addAction(tr("Go to my &profile")); |
| 193 QActionGroup* pages_group = new QActionGroup(this); | 194 // action = submenu->addAction(tr("Go to my &history")); |
| 194 pages_group->setExclusive(true); | 195 // } |
| 195 | 196 } |
| 196 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); | 197 } |
| 197 action->setCheckable(true); | 198 |
| 198 page_to_index_map[action] = 0; | 199 { |
| 199 | 200 /* Tools */ |
| 200 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); | 201 QMenu* menu = menubar->addMenu(tr("&Tools")); |
| 201 page_to_index_map[action] = 1; | 202 // { |
| 202 action->setCheckable(true); | 203 // /* Export anime list */ |
| 203 action->setChecked(true); | 204 // QMenu* submenu = menu->addMenu(tr("&Export anime list")); |
| 204 | 205 // |
| 205 action = pages_group->addAction(menu->addAction(tr("&History"))); | 206 // { |
| 206 action->setCheckable(true); | 207 // /* Markdown export */ |
| 207 page_to_index_map[action] = 2; | 208 // QAction* action = submenu->addAction(tr("Export as &Markdown...")); |
| 208 | 209 // } |
| 209 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); | 210 // |
| 210 action->setCheckable(true); | 211 // { |
| 211 page_to_index_map[action] = 3; | 212 // /* XML export */ |
| 212 | 213 // QAction* action = submenu->addAction(tr("Export as MyAnimeList &XML...")); |
| 213 action = pages_group->addAction(menu->addAction(tr("S&earch"))); | 214 // } |
| 214 action->setCheckable(true); | 215 // } |
| 215 page_to_index_map[action] = 4; | 216 // menu->addSeparator(); |
| 216 | 217 // |
| 217 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); | 218 // { |
| 218 action->setCheckable(true); | 219 // QAction* action = menu->addAction(tr("Enable anime &recognition")); |
| 219 page_to_index_map[action] = 5; | 220 // action->setCheckable(true); |
| 220 | 221 // } |
| 221 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); | 222 // |
| 222 action->setCheckable(true); | 223 // { |
| 223 page_to_index_map[action] = 6; | 224 // QAction* action = menu->addAction(tr("Enable auto &sharing")); |
| 224 | 225 // action->setCheckable(true); |
| 225 connect(sidebar, &SideBar::CurrentItemChanged, this, | 226 // } |
| 226 [pages_group](int index) { pages_group->actions()[index]->setChecked(true); }); | 227 // |
| 227 | 228 // { |
| 228 connect(pages_group, &QActionGroup::triggered, this, | 229 // QAction* action = menu->addAction(tr("Enable &auto synchronization")); |
| 229 [this, page_to_index_map](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); }); | 230 // action->setCheckable(true); |
| 230 | 231 // } |
| 231 menu->addSeparator(); | 232 // |
| 232 menu->addAction(tr("Show sidebar")); | 233 // menu->addSeparator(); |
| 233 | 234 |
| 234 menu = menubar->addMenu(tr("&Help")); | 235 { |
| 235 action = menu->addAction(tr("&About Minori"), this, [this] { | 236 QAction* action = menu->addAction(tr("&Settings"), [this] { |
| 236 AboutWindow dialog(this); | 237 SettingsDialog dialog(this); |
| 237 dialog.exec(); | 238 dialog.exec(); |
| 238 }); | 239 }); |
| 239 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | 240 action->setMenuRole(QAction::PreferencesRole); |
| 240 action->setMenuRole(QAction::AboutQtRole); | 241 } |
| 241 | 242 } |
| 243 | |
| 244 { | |
| 245 /* View */ | |
| 246 QMenu* menu = menubar->addMenu(tr("&View")); | |
| 247 | |
| 248 { | |
| 249 /* Pages... */ | |
| 250 std::map<QAction*, int> page_to_index_map = {}; | |
| 251 | |
| 252 QActionGroup* pages_group = new QActionGroup(this); | |
| 253 pages_group->setExclusive(true); | |
| 254 | |
| 255 { | |
| 256 QAction* action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); | |
| 257 action->setCheckable(true); | |
| 258 page_to_index_map[action] = 0; | |
| 259 } | |
| 260 | |
| 261 { | |
| 262 QAction* action = pages_group->addAction(menu->addAction(tr("&Anime List"))); | |
| 263 action->setCheckable(true); | |
| 264 action->setChecked(true); | |
| 265 page_to_index_map[action] = 1; | |
| 266 } | |
| 267 | |
| 268 { | |
| 269 QAction* action = pages_group->addAction(menu->addAction(tr("&History"))); | |
| 270 action->setCheckable(true); | |
| 271 page_to_index_map[action] = 2; | |
| 272 } | |
| 273 | |
| 274 { | |
| 275 QAction* action = pages_group->addAction(menu->addAction(tr("&Statistics"))); | |
| 276 action->setCheckable(true); | |
| 277 page_to_index_map[action] = 3; | |
| 278 } | |
| 279 | |
| 280 { | |
| 281 QAction* action = pages_group->addAction(menu->addAction(tr("S&earch"))); | |
| 282 action->setCheckable(true); | |
| 283 page_to_index_map[action] = 4; | |
| 284 } | |
| 285 | |
| 286 { | |
| 287 QAction* action = pages_group->addAction(menu->addAction(tr("Se&asons"))); | |
| 288 action->setCheckable(true); | |
| 289 page_to_index_map[action] = 5; | |
| 290 } | |
| 291 | |
| 292 { | |
| 293 QAction* action = pages_group->addAction(menu->addAction(tr("&Torrents"))); | |
| 294 action->setCheckable(true); | |
| 295 page_to_index_map[action] = 6; | |
| 296 } | |
| 297 | |
| 298 /* pain in my ass */ | |
| 299 connect(sidebar.get(), &SideBar::CurrentItemChanged, this, | |
| 300 [pages_group](int index) { pages_group->actions()[index]->setChecked(true); }); | |
| 301 | |
| 302 connect(pages_group, &QActionGroup::triggered, this, | |
| 303 [this, page_to_index_map](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); }); | |
| 304 } | |
| 305 | |
| 306 menu->addSeparator(); | |
| 307 | |
| 308 // { | |
| 309 // QAction* action = menu->addAction(tr("Show sidebar")); | |
| 310 // } | |
| 311 } | |
| 312 | |
| 313 { | |
| 314 /* Help */ | |
| 315 QMenu* menu = menubar->addMenu(tr("&Help")); | |
| 316 | |
| 317 { | |
| 318 /* About Minori */ | |
| 319 menu->addAction(tr("&About Minori"), this, [this] { | |
| 320 AboutWindow dialog(this); | |
| 321 dialog.exec(); | |
| 322 }); | |
| 323 } | |
| 324 | |
| 325 { | |
| 326 /* About Qt */ | |
| 327 QAction* action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | |
| 328 action->setMenuRole(QAction::AboutQtRole); | |
| 329 } | |
| 330 } | |
| 242 /* QMainWindow will delete the old one for us, | 331 /* QMainWindow will delete the old one for us, |
| 243 according to the docs */ | 332 according to the docs */ |
| 244 setMenuBar(menubar); | 333 setMenuBar(menubar); |
| 245 | 334 |
| 246 /* Toolbar */ | 335 /* Toolbar */ |
| 336 | |
| 247 /* remove old toolbar(s) */ | 337 /* remove old toolbar(s) */ |
| 248 QList<QToolBar*> toolbars = findChildren<QToolBar*>(); | 338 for (QToolBar*& t : findChildren<QToolBar*>(Qt::FindDirectChildrenOnly)) { |
| 249 for (auto& t : toolbars) { | |
| 250 removeToolBar(t); | 339 removeToolBar(t); |
| 251 delete t; | 340 delete t; |
| 252 } | 341 } |
| 253 | 342 |
| 254 QToolBar* toolbar = new QToolBar(this); | 343 { |
| 255 toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), | 344 /* Toolbar */ |
| 256 [this] { AsyncSynchronize(stack); }); | 345 QToolBar* toolbar = new QToolBar(this); |
| 257 toolbar->addSeparator(); | 346 toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), |
| 258 | 347 [this] { AsyncSynchronize(stack.get()); }); |
| 259 QToolButton* button = new QToolButton(toolbar); | 348 |
| 260 | 349 toolbar->addSeparator(); |
| 261 menu = new QMenu(button); | 350 |
| 262 action = menu->addAction(tr("Add new folder...")); | 351 { |
| 263 | 352 QToolButton* button = new QToolButton(toolbar); |
| 264 button->setMenu(menu); | 353 { |
| 265 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); | 354 QMenu* menu = new QMenu(button); |
| 266 button->setPopupMode(QToolButton::InstantPopup); | 355 QAction* action = menu->addAction(tr("...")); |
| 267 toolbar->addWidget(button); | 356 |
| 268 | 357 button->setMenu(menu); |
| 269 button = new QToolButton(toolbar); | 358 } |
| 270 | 359 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); |
| 271 menu = new QMenu(button); | 360 button->setPopupMode(QToolButton::InstantPopup); |
| 272 action = menu->addAction(tr("Placeholder")); | 361 toolbar->addWidget(button); |
| 273 | 362 } |
| 274 button->setMenu(menu); | 363 |
| 275 button->setIcon(QIcon(":/icons/24x24/application-export.png")); | 364 { |
| 276 button->setPopupMode(QToolButton::InstantPopup); | 365 QToolButton* button = new QToolButton(toolbar); |
| 277 toolbar->addWidget(button); | 366 |
| 278 | 367 { |
| 279 toolbar->addSeparator(); | 368 QMenu* menu = new QMenu(button); |
| 280 toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { | 369 QAction* action = menu->addAction(tr("...")); |
| 281 SettingsDialog dialog(this); | 370 |
| 282 dialog.exec(); | 371 button->setMenu(menu); |
| 283 }); | 372 } |
| 284 addToolBar(toolbar); | 373 |
| 374 button->setIcon(QIcon(":/icons/24x24/application-export.png")); | |
| 375 button->setPopupMode(QToolButton::InstantPopup); | |
| 376 toolbar->addWidget(button); | |
| 377 } | |
| 378 | |
| 379 toolbar->addSeparator(); | |
| 380 toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { | |
| 381 SettingsDialog dialog(this); | |
| 382 dialog.exec(); | |
| 383 }); | |
| 384 addToolBar(toolbar); | |
| 385 } | |
| 285 } | 386 } |
| 286 | 387 |
| 287 void MainWindow::SetActivePage(QWidget* page) { | 388 void MainWindow::SetActivePage(QWidget* page) { |
| 288 this->setCentralWidget(page); | 389 this->setCentralWidget(page); |
| 289 } | 390 } |
