1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#include "main_window.hpp"
#include <QString>
#include <zip.h>
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<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_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
|