diff options
Diffstat (limited to 'src/main_window.cpp')
-rw-r--r-- | src/main_window.cpp | 129 |
1 files changed, 0 insertions, 129 deletions
diff --git a/src/main_window.cpp b/src/main_window.cpp deleted file mode 100644 index 9972ecb..0000000 --- a/src/main_window.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "main_window.hpp" - -#include <QString> -#include <zip.h> - -namespace bookmouse { - -BookmouseApp::BookmouseApp() : m_bookmouse{new Bookmouse()} -{ - setCentralWidget(m_bookmouse); - setup(); -} - -void BookmouseApp::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 BookmouseApp::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, &BookmouseApp::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, &BookmouseApp::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, &BookmouseApp::quit); - - auto nextShortcuts = QList<QKeySequence>{}; - 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, &BookmouseApp::next); - - auto backShortcuts = QList<QKeySequence>{}; - 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, &BookmouseApp::back); -} - -void BookmouseApp::createMenus() -{ - m_menuBar = menuBar()->addMenu(tr("&File")); - m_menuBar->addAction(m_openFile); - m_menuBar->addAction(m_openDirectory); - m_menuBar->addAction(m_quitAction); -} - -void BookmouseApp::createToolBar() -{ - m_toolBar = addToolBar(tr("&Navigation")); - m_toolBar->addAction(m_backAction); - m_toolBar->addAction(m_nextAction); -} - -void BookmouseApp::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_bookmouse->setArchive(archive); - } catch (std::runtime_error& exc) { - qCritical("Failed to change archive"); - } - } else { - qCritical("Unsupported file extension"); - } -} - -void BookmouseApp::openDirectory() -{ - QString directory = QFileDialog::getExistingDirectory( - this, - tr("Open Directory"), - QDir::homePath(), - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - qDebug("Open directory %s", qPrintable(directory)); -} - -void BookmouseApp::quit() -{ - QCoreApplication::quit(); -} - -void BookmouseApp::next() -{ - qDebug("Next"); - m_bookmouse->next(); -} - -void BookmouseApp::back() -{ - qDebug("Back"); - m_bookmouse->back(); -} - -} // namespace bookmouse |