summaryrefslogtreecommitdiff
path: root/src/main_window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main_window.cpp')
-rw-r--r--src/main_window.cpp91
1 files changed, 57 insertions, 34 deletions
diff --git a/src/main_window.cpp b/src/main_window.cpp
index 61b3b65..b05507c 100644
--- a/src/main_window.cpp
+++ b/src/main_window.cpp
@@ -1,9 +1,7 @@
#include "main_window.hpp"
#include <QString>
-#include <minizip-ng/mz.h>
-#include <minizip-ng/mz_strm_buf.h>
-#include <minizip-ng/mz_strm_os.h>
+#include <zip.h>
namespace getsuyomi {
@@ -15,13 +13,18 @@ GetsuyomiApp::GetsuyomiApp() : m_getsuyomi{new Getsuyomi()}
void GetsuyomiApp::setup()
{
- createActions();
- createMenus();
-
QCoreApplication::setApplicationName(AppName);
QCoreApplication::setApplicationVersion(AppVersionString);
setWindowTitle(AppName);
+ createActions();
+ createMenus();
+ createToolBar();
+
+ constexpr int minimumWidth = 640;
+ constexpr int minimumHeight = 480;
+ setMinimumSize(minimumWidth, minimumHeight);
+
show();
}
@@ -41,14 +44,39 @@ void GetsuyomiApp::createActions()
m_quitAction->setShortcuts(QKeySequence::Quit);
m_quitAction->setStatusTip(tr("Quit"));
connect(m_quitAction, &QAction::triggered, this, &GetsuyomiApp::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, &GetsuyomiApp::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, &GetsuyomiApp::back);
}
void GetsuyomiApp::createMenus()
{
- m_fileMenu = menuBar()->addMenu(tr("&File"));
- m_fileMenu->addAction(m_openFile);
- m_fileMenu->addAction(m_openDirectory);
- m_fileMenu->addAction(m_quitAction);
+ 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()
@@ -58,7 +86,17 @@ void GetsuyomiApp::openFile()
tr("Open Archive"),
QDir::homePath(),
tr("Archive types (*.zip *.cbz *.cbr *.gz)"));
- qDebug("Open file %s\n", qPrintable(filename));
+
+ 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()
@@ -69,38 +107,23 @@ void GetsuyomiApp::openDirectory()
QDir::homePath(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
qDebug("Open directory %s", qPrintable(directory));
-
- auto* stream = mz_stream_os_create();
- if (stream == nullptr) {
- qCritical("Nullpointer - stream");
- return;
- }
-
- auto* bufStream = mz_stream_buffered_create();
- if (stream == nullptr) {
- qCritical("Nullpointer - bufStream");
- return;
- }
-
- mz_stream_buffered_open(bufStream, nullptr, MZ_OPEN_MODE_READ);
- mz_stream_buffered_set_base(bufStream, stream);
-
}
void GetsuyomiApp::quit()
{
- printf("Quit!\n");
QCoreApplication::quit();
}
-Getsuyomi::Getsuyomi()
+void GetsuyomiApp::next()
{
- m_layout = new QVBoxLayout();
-
- auto* label = new QLabel(AppName);
- m_layout->addWidget(label);
+ qDebug("Next");
+ m_getsuyomi->next();
+}
- setLayout(m_layout);
+void GetsuyomiApp::back()
+{
+ qDebug("Back");
+ m_getsuyomi->back();
}
} // namespace getsuyomi