#include "main_window.hpp" #include #include namespace getsuyomi { GetsuyomiApp::GetsuyomiApp() : m_getsuyomi{new Getsuyomi()} { setCentralWidget(m_getsuyomi); setup(); } void GetsuyomiApp::setup() { QCoreApplication::setApplicationName(AppName); QCoreApplication::setApplicationVersion(AppVersionString); setWindowTitle(AppName); createActions(); createMenus(); createToolBar(); constexpr int minimumWidth = 640; constexpr int minimumHeight = 480; setMinimumSize(minimumWidth, minimumHeight); show(); } void GetsuyomiApp::createActions() { m_openFile = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen), tr("&Open File"), this); m_openFile->setShortcuts(QKeySequence::Open); m_openFile->setStatusTip(tr("Open a file")); connect(m_openFile, &QAction::triggered, this, &GetsuyomiApp::openFile); m_openDirectory = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::FolderOpen), tr("Open Directory"), this); m_openDirectory->setShortcut(Qt::CTRL | Qt::ALT | Qt::Key_O); m_openDirectory->setStatusTip(tr("Open a directory")); connect(m_openDirectory, &QAction::triggered, this, &GetsuyomiApp::openDirectory); m_quitAction = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::ApplicationExit), tr("&Quit"), this); m_quitAction->setShortcuts(QKeySequence::Quit); m_quitAction->setStatusTip(tr("Quit")); connect(m_quitAction, &QAction::triggered, this, &GetsuyomiApp::quit); auto nextShortcuts = QList{}; nextShortcuts.append(QKeySequence{Qt::Key_L}); nextShortcuts.append(QKeySequence{Qt::Key_Right}); nextShortcuts.append(QKeySequence{Qt::Key_Down}); m_nextAction = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::GoNext), tr("Next"), this); m_nextAction->setShortcuts(nextShortcuts); m_nextAction->setStatusTip(tr("Next")); connect(m_nextAction, &QAction::triggered, this, &GetsuyomiApp::next); auto backShortcuts = QList{}; backShortcuts.append(QKeySequence{Qt::Key_H}); backShortcuts.append(QKeySequence{Qt::Key_Left}); backShortcuts.append(QKeySequence{Qt::Key_Up}); m_backAction = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::GoPrevious), tr("Back"), this); m_backAction->setShortcuts(backShortcuts); m_backAction->setStatusTip(tr("Back")); connect(m_backAction, &QAction::triggered, this, &GetsuyomiApp::back); } void GetsuyomiApp::createMenus() { m_menuBar = menuBar()->addMenu(tr("&File")); m_menuBar->addAction(m_openFile); m_menuBar->addAction(m_openDirectory); m_menuBar->addAction(m_quitAction); } void GetsuyomiApp::createToolBar() { m_toolBar = addToolBar(tr("&Navigation")); m_toolBar->addAction(m_backAction); m_toolBar->addAction(m_nextAction); } void GetsuyomiApp::openFile() { auto filename = QFileDialog::getOpenFileName( this, tr("Open Archive"), QDir::homePath(), tr("Archive types (*.zip *.cbz *.cbr *.gz)")); if (filename.endsWith(".zip")) { try { auto* archive = new ZipArchive(filename); m_getsuyomi->setArchive(archive); } catch (std::runtime_error& exc) { qCritical("Failed to change archive"); } } else { qCritical("Unsupported file extension"); } } void GetsuyomiApp::openDirectory() { QString directory = QFileDialog::getExistingDirectory( this, tr("Open Directory"), QDir::homePath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); qDebug("Open directory %s", qPrintable(directory)); } void GetsuyomiApp::quit() { QCoreApplication::quit(); } void GetsuyomiApp::next() { qDebug("Next"); m_getsuyomi->next(); } void GetsuyomiApp::back() { qDebug("Back"); m_getsuyomi->back(); } } // namespace getsuyomi