remarkable_tool/main_window.cpp

73 lines
2.3 KiB
C++

/* Copyright 2021, Michele Santullo
* This file is part of remarkable_tool.
*
* remarkable_tool is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Remarkable_tool is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with remarkable_tool. If not, see <http://www.gnu.org/licenses/>.
*/
#include "main_window.hpp"
#include "notebook_tree_model.hpp"
#include "notebook_tree.hpp"
#include "config.h"
#include <QTreeView>
#include <QAction>
#include <QMenu>
#include <QMenuBar>
#include <QApplication>
#include <QHBoxLayout>
#include <QTextEdit>
#include <vector>
namespace duck {
MainWindow::MainWindow (Node* tree) :
m_tree(new QTreeView),
m_tree_model(new NotebookTreeModel(tree, m_tree)),
m_file_menu(menuBar()->addMenu("&File")),
m_gen_dele_list(new QAction(QPixmap("cog_64.png"), "Generate list", this)),
m_quit_action(new QAction(QPixmap("close_64.png"), "Quit", this)),
m_central_layout(new QHBoxLayout),
m_output(new QTextEdit)
{
setWindowTitle(APP_NAME);
QWidget* const main_widget = new QWidget;
setCentralWidget(main_widget);
main_widget->setLayout(m_central_layout);
m_central_layout->addWidget(m_tree);
m_central_layout->addWidget(m_output);
m_tree->setModel(m_tree_model);
m_file_menu->addAction(m_gen_dele_list);
connect(m_gen_dele_list, &QAction::triggered, this, &MainWindow::generate_dele_list);
m_quit_action->setShortcuts(QKeySequence::Quit);
m_file_menu->addAction(m_quit_action);
connect(m_quit_action, &QAction::triggered, this, &QApplication::quit);
}
MainWindow::~MainWindow() noexcept = default;
void MainWindow::generate_dele_list() {
std::vector<const NotebookInfo*> list(make_list_of_deleted(m_tree_model->root_node()));
QString out_text;
for (const auto& nb : list) {
for (const auto& f : nb->files) {
out_text += QString(REMARKABLE_BASE_PATH) + QString::fromStdString(f) + "/n";
}
}
m_output->setText(out_text);
}
} //namespace duck