MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QFile styleFile(":/style.css"); styleFile.open(QFile::ReadOnly); QString styleSheet = QLatin1String(styleFile.readAll()); qApp->setStyleSheet(styleSheet); QPixmap window_icon; QFile iconFile(":/icon.png"); iconFile.open(QFile::ReadOnly); QByteArray icon_data = iconFile.readAll(); window_icon.loadFromData(icon_data); qApp->setWindowIcon(QIcon(window_icon)); awesome = new QtAwesome(qApp); settings = new Settings(this); window_watcher = new WindowWatcher(this); anitomy = new AnitomyWrapper(); event_timer = new QTimer(this); watch_timer = new QTimer(this); uptime_timer = new QElapsedTimer; progress_bar = new QProgressBar(ui->statusBar); over = new Overlay(this); torrent_refresh_time = 0; user_refresh_time = settings->getValue(Settings::UserRefreshTime, D_USER_REFRESH_TIME) .toInt(); download_rule = 0; download_count = 0; hasUser = false; uptime_timer->start(); watch_timer->setSingleShot(true); awesome->initFontAwesome(); bool check_for_updates = settings->getValue(Settings::CheckUpdates, D_CHECK_FOR_UPDATES).toBool(); if (check_for_updates) { connect(FvUpdater::sharedUpdater(), &FvUpdater::restartRequested, [&]() { // NOLINT QString app = QApplication::applicationFilePath(); QStringList arguments = QApplication::arguments(); QString wd = QDir::currentPath(); QProcess::startDetached(app, arguments, wd); elegantClose(true); }); FvUpdater::sharedUpdater()->CheckForUpdatesSilent(); } QFont font = ui->listTabs->tabBar()->font(); font.setCapitalization(QFont::Capitalize); ui->listTabs->tabBar()->setFont(font); int currentYear = QDate::currentDate().year(); int lowerYear = currentYear - 10; while (currentYear > lowerYear) { ui->comboYear->addItem(QString::number(currentYear)); currentYear--; } QWidget *container = new QWidget(ui->scrollArea); layout = new FlowLayout(container); ui->scrollArea->setWidget(container); container->setLayout(layout); QWidget *container2 = new QWidget(ui->scrollArea_2); layout2 = new FlowLayout(container2); layout2->disableSort(); ui->scrollArea_2->setWidget(container2); container2->setLayout(layout2); QVariantMap black; black.insert("color", QColor(0, 0, 0)); black.insert("color-active", QColor(0, 0, 0)); black.insert("color-disabled", QColor(0, 0, 0)); black.insert("color-selected", QColor(0, 0, 0)); ui->airingButton->setIcon(awesome->icon(fa::clocko, black)); ui->torrentsButton->setIcon(awesome->icon(fa::rss, black)); ui->animeButton->setIcon(awesome->icon(fa::bars, black)); ui->seasonsButton->setIcon(awesome->icon(fa::th, black)); ui->statisticsButton->setIcon(awesome->icon(fa::piechart, black)); ui->tabWidget->tabBar()->hide(); ui->tabWidget->setCurrentIndex(UserTabs::tAnime); ui->listTabs->setCurrentIndex(0); ui->statusBar->addWidget(progress_bar); ui->statusBar->layout()->setContentsMargins(1, 0, 0, 0); progress_bar->setRange(0, 100); progress_bar->setValue(5); progress_bar->setFormat("Authorizing"); QSettings s; restoreGeometry(s.value("mainWindowGeometry").toByteArray()); restoreState(s.value("mainWindowState").toByteArray()); connect(&user_future_watcher, SIGNAL(finished()), SLOT(userLoaded())); connect(&user_list_future_watcher, SIGNAL(finished()), SLOT(userListLoaded())); connect(ui->animeButton, SIGNAL(clicked()), SLOT(showAnimeTab())); connect(ui->airingButton, SIGNAL(clicked()), SLOT(showAiringTab())); connect(ui->torrentsButton, SIGNAL(clicked()), SLOT(showTorrentsTab())); connect(ui->seasonsButton, SIGNAL(clicked()), SLOT(showBrowseTab())); connect(ui->actionSettings, SIGNAL(triggered()), SLOT(showSettings())); connect(ui->statisticsButton, SIGNAL(clicked()), SLOT(showStatisticsTab())); connect(ui->actionExit, &QAction::triggered, [&, this]() { // NOLINT this->elegantClose(); }); connect(ui->actionAbout, &QAction::triggered, [&, this]() { // NOLINT About *about = new About(this); about->show(); }); connect(ui->actionHelp, &QAction::triggered, [&, this]() { // NOLINT QDesktopServices::openUrl(QUrl("http://app.shinjiru.me/support.php")); }); connect(ui->actionRL, &QAction::triggered, [&, this]() { // NOLINT loadUser(); }); connect(ui->actionAS, &QAction::triggered, [&]() { // NOLINT SearchPanel *sp = new SearchPanel(this); sp->show(); }); connect(ui->actionARR, &QAction::triggered, [&, this]() { // NOLINT SettingsDialog *s = new SettingsDialog(this); s->showSmartTitles(); connect(s, &QDialog::accepted, [&, this]() { // NOLINT Settings set; toggleAnimeRecognition( set.getValue(Settings::AnimeRecognitionEnabled, D_ANIME_RECOGNITION) .toBool()); torrents_enabled = set.getValue(Settings::TorrentsEnabled, D_TORRENTS_ENABLED).toBool(); reloadSmartTitles(); reloadRules(); }); }); connect(qApp, SIGNAL(aboutToQuit()), SLOT(elegantClose())); connect(ui->actionVAL, SIGNAL(triggered()), SLOT(viewAnimeList())); connect(ui->actionVD, SIGNAL(triggered()), SLOT(viewDashboard())); connect(ui->actionVP, SIGNAL(triggered()), SLOT(viewProfile())); connect(ui->actionEAR, SIGNAL(triggered(bool)), SLOT(toggleAnimeRecognition(bool))); connect(ui->actionExport, SIGNAL(triggered()), SLOT(exportListJSON())); connect(ui->actionUpdate, SIGNAL(triggered()), FvUpdater::sharedUpdater(), SLOT(CheckForUpdatesNotSilent())); connect(window_watcher, SIGNAL(title_found(QString)), SLOT(watch(QString))); connect(watch_timer, SIGNAL(timeout()), SLOT(updateEpisode())); connect(event_timer, SIGNAL(timeout()), SLOT(eventTick())); connect(ui->torrentTable, SIGNAL(customContextMenuRequested(QPoint)), SLOT(torrentContextMenu(QPoint))); connect(ui->torrentFilter, SIGNAL(textChanged(QString)), SLOT(filterTorrents(QString))); connect(ui->chkHideUnknown, SIGNAL(toggled(bool)), SLOT(filterTorrents(bool))); connect(ui->refreshButton, SIGNAL(clicked()), SLOT(refreshTorrentListing())); connect(ui->actionEAR, SIGNAL(toggled(bool)), SLOT(applyEAR())); connect(ui->tabWidget, &QTabWidget::currentChanged, [&, this]( // NOLINT int tab) { if (tab != 0) { this->over->removeDrawing("blank_table"); this->over->removeDrawing("no anime"); ui->listTabs->show(); ui->listFilterLineEdit->show(); } else { this->filterList(3); if (hasUser && (User::sharedUser()->getAnimeList().count() == 0)) { this->addNoAnimePrompt(); } } }); ui->actionEAR->setChecked( settings->getValue(Settings::AnimeRecognitionEnabled, D_ANIME_RECOGNITION) .toBool()); this->toggleAnimeRecognition(ui->actionEAR->isChecked()); QString genrelist = "Action, Adult, Adventure, Cars, Comedy, Dementia, Demons, Doujinshi, " "Drama, Ecchi, Fantasy, Game, Gender Bender, Harem, Hentai, Historical, " "Horror, Josei, Kids, Magic, Martial Arts, Mature, Mecha, Military, " "Motion Comic, Music, Mystery, Mythological , Parody, Police, " "Psychological, Romance, Samurai, School, Sci-Fi, Seinen, Shoujo, Shoujo " "Ai, Shounen, Shounen Ai, Slice of Life, Space, Sports, Super Power, " "Supernatural, Thriller, Tragedy, Vampire, Yaoi, Yuri"; QStringList genres = genrelist.split(", "); for (QString genre : genres) { QCheckBox *chk = new QCheckBox(); chk->setText(genre); chk->setTristate(true); ui->genreList->addWidget(chk); } connect(ui->listFilterLineEdit, SIGNAL(textChanged(QString)), SLOT(filterList(QString))); connect(ui->listFilterLineEdit, SIGNAL(returnPressed()), SLOT(showSearch())); connect(ui->listTabs, SIGNAL(currentChanged(int)), SLOT(filterList(int))); connect(ui->browseButton, SIGNAL(clicked()), SLOT(loadBrowserData())); this->show(); createActions(); initTray(); trayIcon->show(); int result = API::sharedAPI()->verifyAPI(); if (result == AniListAPI::OK) { connect(API::sharedAPI()->sharedAniListAPI(), &AniListAPI::access_granted, [&, this]() { // NOLINT progress_bar->setValue(10); progress_bar->setFormat("Access granted"); loadUser(); event_timer->start(1000); }); connect(API::sharedAPI()->sharedAniListAPI(), &AniListAPI::access_denied, [&, this](QString error) { // NOLINT qCritical() << error; if (isVisible()) { QMessageBox::critical(this, "Shinjiru", tr("Error: ") + error); } }); } else if (result == AniListAPI::NO_CONNECTION) { qDebug() << "Starting Shinjiru in offline mode"; hasUser = User::sharedUser()->loadLocal(); } reloadRules(); }
Void PlaYUVerApp::createActions() { m_arrayActions.resize( TOTAL_ACT ); // ------------ File ------------ m_arrayActions[OPEN_ACT] = new QAction( QIcon( ":/images/open.png" ), tr( "&Open" ), this ); m_arrayActions[OPEN_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogOpenButton ) ); m_arrayActions[OPEN_ACT]->setShortcuts( QKeySequence::Open ); m_arrayActions[OPEN_ACT]->setStatusTip( tr( "Open stream" ) ); connect( m_arrayActions[OPEN_ACT], SIGNAL( triggered() ), this, SLOT( open() ) ); m_arrayRecentFilesActions.resize( MAX_RECENT_FILES ); for( Int i = 0; i < MAX_RECENT_FILES; i++ ) { m_arrayRecentFilesActions[i] = new QAction( this ); m_arrayRecentFilesActions[i]->setVisible( false ); connect( m_arrayRecentFilesActions[i], SIGNAL( triggered() ), this, SLOT( openRecent() ) ); } m_arrayActions[SAVE_ACT] = new QAction( QIcon( ":/images/save.png" ), tr( "&Save Frame" ), this ); m_arrayActions[SAVE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogSaveButton ) ); m_arrayActions[SAVE_ACT]->setShortcuts( QKeySequence::SaveAs ); m_arrayActions[SAVE_ACT]->setStatusTip( tr( "Save current frame" ) ); connect( m_arrayActions[SAVE_ACT], SIGNAL( triggered() ), this, SLOT( save() ) ); m_arrayActions[FORMAT_ACT] = new QAction( tr( "&Format" ), this ); m_arrayActions[FORMAT_ACT]->setIcon( QIcon::fromTheme( "transform-scale", QIcon( ":/images/configuredialog.png" ) ) ); m_arrayActions[FORMAT_ACT]->setShortcut( Qt::CTRL + Qt::Key_F ); m_arrayActions[FORMAT_ACT]->setStatusTip( tr( "Open format dialog" ) ); connect( m_arrayActions[FORMAT_ACT], SIGNAL( triggered() ), this, SLOT( format() ) ); m_arrayActions[RELOAD_ACT] = new QAction( tr( "&Reload" ), this ); m_arrayActions[RELOAD_ACT]->setIcon( style()->standardIcon( QStyle::SP_BrowserReload ) ); m_arrayActions[RELOAD_ACT]->setShortcut( Qt::CTRL + Qt::Key_R ); m_arrayActions[RELOAD_ACT]->setShortcut( Qt::Key_F5 ); m_arrayActions[RELOAD_ACT]->setStatusTip( tr( "Reload current sequence" ) ); connect( m_arrayActions[RELOAD_ACT], SIGNAL( triggered() ), this, SLOT( reload() ) ); m_arrayActions[RELOAD_ALL_ACT] = new QAction( tr( "Reload All" ), this ); m_arrayActions[RELOAD_ALL_ACT]->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_R ); m_arrayActions[RELOAD_ALL_ACT]->setStatusTip( tr( "Reload all sequences" ) ); connect( m_arrayActions[RELOAD_ALL_ACT], SIGNAL( triggered() ), this, SLOT( reloadAll() ) ); m_arrayActions[LOAD_ALL_ACT] = new QAction( tr( "Preload" ), this ); m_arrayActions[LOAD_ALL_ACT]->setStatusTip( tr( "Load sequence into memory (caution)" ) ); connect( m_arrayActions[LOAD_ALL_ACT], SIGNAL( triggered() ), this, SLOT( loadAll() ) ); m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this ); m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) ); m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) ); connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), m_pcWindowHandle, SLOT( removeActiveSubWindow() ) ); m_arrayActions[CLOSEALL_ACT] = new QAction( tr( "Close &All" ), this ); m_arrayActions[CLOSEALL_ACT]->setStatusTip( tr( "Close all the windows" ) ); connect( m_arrayActions[CLOSEALL_ACT], SIGNAL( triggered() ), m_pcWindowHandle, SLOT( removeAllSubWindow() ) ); m_arrayActions[EXIT_ACT] = new QAction( tr( "E&xit" ), this ); m_arrayActions[EXIT_ACT]->setShortcuts( QKeySequence::Quit ); m_arrayActions[EXIT_ACT]->setStatusTip( tr( "Exit the application" ) ); connect( m_arrayActions[EXIT_ACT], SIGNAL( triggered() ), qApp, SLOT( closeAllWindows() ) ); // ------------ View ------------ mapperZoom = new QSignalMapper( this ); connect( mapperZoom, SIGNAL( mapped(int) ), this, SLOT( scaleFrame(int) ) ); m_arrayActions[ZOOM_IN_ACT] = new QAction( tr( "Zoom &In (+25%)" ), this ); m_arrayActions[ZOOM_IN_ACT]->setIcon( QIcon::fromTheme( "zoom-in", QIcon( ":/images/zoomin.png" ) ) ); m_arrayActions[ZOOM_IN_ACT]->setShortcut( tr( "Ctrl++" ) ); m_arrayActions[ZOOM_IN_ACT]->setStatusTip( tr( "Scale the image up by 25%" ) ); connect( m_arrayActions[ZOOM_IN_ACT], SIGNAL( triggered() ), mapperZoom, SLOT( map() ) ); mapperZoom->setMapping( m_arrayActions[ZOOM_IN_ACT], 125 ); m_arrayActions[ZOOM_OUT_ACT] = new QAction( tr( "Zoom &Out (-25%)" ), this ); m_arrayActions[ZOOM_OUT_ACT]->setIcon( QIcon::fromTheme( "zoom-out", QIcon( ":/images/zoomout.png" ) ) ); m_arrayActions[ZOOM_OUT_ACT]->setShortcut( tr( "Ctrl+-" ) ); m_arrayActions[ZOOM_OUT_ACT]->setStatusTip( tr( "Scale the image down by 25%" ) ); connect( m_arrayActions[ZOOM_OUT_ACT], SIGNAL( triggered() ), mapperZoom, SLOT( map() ) ); mapperZoom->setMapping( m_arrayActions[ZOOM_OUT_ACT], 80 ); m_arrayActions[ZOOM_NORMAL_ACT] = new QAction( tr( "&Normal Size" ), this ); m_arrayActions[ZOOM_NORMAL_ACT]->setIcon( QIcon::fromTheme( "zoom-original", QIcon( ":/images/zoomtonormal.png" ) ) ); m_arrayActions[ZOOM_NORMAL_ACT]->setShortcut( tr( "Ctrl+N" ) ); m_arrayActions[ZOOM_NORMAL_ACT]->setStatusTip( tr( "Show the image at its original size" ) ); connect( m_arrayActions[ZOOM_NORMAL_ACT], SIGNAL( triggered() ), this, SLOT( normalSize() ) ); m_arrayActions[ZOOM_FIT_ACT] = new QAction( tr( "Zoom to &Fit" ), this ); m_arrayActions[ZOOM_FIT_ACT]->setIcon( QIcon::fromTheme( "zoom-fit-best", QIcon( ":/images/fittowindow.png" ) ) ); m_arrayActions[ZOOM_FIT_ACT]->setStatusTip( tr( "Zoom in or out to fit on the window." ) ); connect( m_arrayActions[ZOOM_FIT_ACT], SIGNAL( triggered() ), this, SLOT( zoomToFit() ) ); m_arrayActions[ZOOM_FIT_ALL_ACT] = new QAction( tr( "Zoom to Fit All" ), this ); //m_arrayActions[ZOOM_FIT_ALL_ACT]->setIcon( QIcon::fromTheme( "zoom-fit-best", QIcon( ":/images/fittowindow.png" ) ) ); m_arrayActions[ZOOM_FIT_ALL_ACT]->setStatusTip( tr( "Apply zoom to fit to all windows" ) ); connect( m_arrayActions[ZOOM_FIT_ALL_ACT], SIGNAL( triggered() ), this, SLOT( zoomToFitAll() ) ); m_appModuleVideo->createActions(); m_appModuleQuality->createActions(); m_appModuleExtensions->createActions(); m_pcWindowHandle->createActions(); // ------------ About ------------ #ifdef USE_FERVOR m_arrayActions[UPDATE_ACT] = new QAction( tr( "&Update" ), this ); m_arrayActions[UPDATE_ACT]->setStatusTip( tr( "Check for updates" ) ); connect( m_arrayActions[UPDATE_ACT], SIGNAL( triggered() ), FvUpdater::sharedUpdater(), SLOT( CheckForUpdatesNotSilent() ) ); #endif m_arrayActions[ABOUT_ACT] = new QAction( tr( "&About" ), this ); m_arrayActions[ABOUT_ACT]->setStatusTip( tr( "Show the application's About box" ) ); connect( m_arrayActions[ABOUT_ACT], SIGNAL( triggered() ), this, SLOT( about() ) ); m_arrayActions[ABOUTQT_ACT] = new QAction( tr( "About &Qt" ), this ); m_arrayActions[ABOUTQT_ACT]->setIcon( QIcon( ":images/qt.png" ) ); m_arrayActions[ABOUTQT_ACT]->setStatusTip( tr( "Show the Qt library's About box" ) ); connect( m_arrayActions[ABOUTQT_ACT], SIGNAL( triggered() ), qApp, SLOT( aboutQt() ) ); }