The Note Binder is a Note Organizing Application with a built-in Application Launcher to compliment Note Taking applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1572 lines
67 KiB

/* DrewTechs
* Note Binder
* @Version 1.0
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
init();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_unfiledNotes_Button_clicked()
{
UnfiledNotes* uiUnfiledNotes = new UnfiledNotes(uiSettings->applicationLaunchers);
if(!uiUnfiledNotes->exec()) return;
QString extension = uiUnfiledNotes->getExtension();
runUnfiledNotesApplication(extension);
}
void MainWindow::runUnfiledNotesApplication(QString extension)
{
int appLauncher_idx = 0; // Count up to the Total Number of Applicaiton Launchers available
for(appLauncher_idx = 0; appLauncher_idx < uiSettings->applicationLaunchers.size(); appLauncher_idx++)
{
int extensions_idx = 0; // Count up to the Total Number of Extensions in all file Launchers
for(extensions_idx = 0; extensions_idx < uiSettings->applicationLaunchers.at(appLauncher_idx)->getApplicationExtensions().size(); extensions_idx++)
{
if(uiSettings->applicationLaunchers.at(appLauncher_idx)->getSingleApplicationExtension(extensions_idx) == extension)
{
QObject *parent = new QObject();
QString program = uiSettings->applicationLaunchers.at(appLauncher_idx)->getApplicationLocation();
QStringList arguments; // No Additional Arguments
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments, QIODevice::ReadWrite);
}
}
}
}
void MainWindow::init()
{
/* Set Icons */
ui->newSection_Button->setIcon(QIcon("../NoteBinder/Icons/NewSectionIcon.png"));
ui->newSection_Button->setIconSize(QSize(32,32));
ui->actionNew_Section->setIcon(QIcon("../NoteBinder/Icons/NewSectionIcon.png"));
ui->newSectionGroup_Button->setIcon(QIcon("../NoteBinder/Icons/NewSectionGroupIcon.png"));
ui->newSectionGroup_Button->setIconSize(QSize(32,32));
ui->actionNew_Section_Group->setIcon(QIcon("../NoteBinder/Icons/NewSectionGroupIcon.png"));
ui->newNotebook_Button->setIcon(QIcon("../NoteBinder/Icons/NewNotebookIcon.png"));
ui->newNotebook_Button->setIconSize(QSize(32,32));
ui->actionNew_Notebook->setIcon(QIcon("../NoteBinder/Icons/NewNotebookIcon.png"));
ui->unfiledNotes_Button->setIcon(QIcon("../NoteBinder/Icons/UnfiledNotesIcon.png"));
ui->unfiledNotes_Button->setIconSize(QSize(32,32));
ui->actionUnfiled_Notes->setIcon(QIcon("../NoteBinder/Icons/UnfiledNotesIcon.png"));
ui->openSection_Button->setIcon(QIcon("../NoteBinder/Icons/OpenSectionIcon.png"));
ui->openSection_Button->setIconSize(QSize(32,32));
ui->actionOpen_Section->setIcon(QIcon("../NoteBinder/Icons/OpenSectionIcon.png"));
ui->openNotebook_Button->setIcon(QIcon("../NoteBinder/Icons/OpenNotebookIcon.png"));
ui->openNotebook_Button->setIconSize(QSize(32,32));
ui->actionOpen_Notebook->setIcon(QIcon("../NoteBinder/Icons/OpenNotebookIcon.png"));
ui->importSection_Button->setIcon(QIcon("../NoteBinder/Icons/ImportSectionIcon.png"));
ui->importSection_Button->setIconSize(QSize(32,32));
ui->actionImport_Section->setIcon(QIcon("../NoteBinder/Icons/ImportSectionIcon.png"));
ui->exportSection_Button->setIcon(QIcon("../NoteBinder/Icons/ExportSectionIcon.png"));
ui->exportSection_Button->setIconSize(QSize(32,32));
ui->actionExport_Section->setIcon(QIcon("../NoteBinder/Icons/ExportSectionIcon.png"));
ui->deleteSelectedItem_Button->setIcon(QIcon("../NoteBinder/Icons/DeleteItemIcon.png"));
ui->deleteSelectedItem_Button->setIconSize(QSize(32,32));
ui->actionDeleteItem->setIcon(QIcon("../NoteBinder/Icons/DeleteItemIcon.png"));
ui->refreshNotebookListButton->setIcon(QIcon("../NoteBinder/Icons/RefreshNotebookListIcon.png"));
ui->refreshNotebookListButton->setIconSize(QSize(40,40));
ui->actionRefresh_Notebook_List->setIcon(QIcon("../NoteBinder/Icons/RefreshNotebookListIcon.png"));
ui->copyItem_Button->setIcon(QIcon("../NoteBinder/Icons/CopyItemIcon.png"));
ui->copyItem_Button->setIconSize(QSize(32,32));
ui->actionCopy_Item->setIcon(QIcon("../NoteBinder/Icons/CopyItemIcon.png"));
ui->moveItem_Button->setIcon(QIcon("../NoteBinder/Icons/MoveItemIcon.png"));
ui->moveItem_Button->setIconSize(QSize(32,32));
ui->actionMove_Item->setIcon(QIcon("../NoteBinder/Icons/MoveItemIcon.png"));
ui->generalSettings_Button->setIcon(QIcon("../NoteBinder/Icons/SettingsIcon.png"));
ui->generalSettings_Button->setIconSize(QSize(32,32));
ui->actionSettings->setIcon(QIcon("../NoteBinder/Icons/SettingsIcon.png"));
ui->closeNotebook_Button->setIcon(QIcon("../NoteBinder/Icons/CloseNotebookIcon.png"));
ui->closeNotebook_Button->setIconSize(QSize(32,32));
ui->actionClose_Notebook->setIcon(QIcon("../NoteBinder/Icons/CloseNotebookIcon.png"));
ui->closeAllNotebooksButton->setIcon(QIcon("../NoteBinder/Icons/CloseAllNotebooksIcon.png"));
ui->closeAllNotebooksButton->setIconSize(QSize(32,32));
ui->actionClose_All_Notebooks->setIcon(QIcon("../NoteBinder/Icons/CloseAllNotebooksIcon.png"));
ui->itemPropertiesButton->setIcon(QIcon("../NoteBinder/Icons/ItemPropertiesIcon.png"));
ui->itemPropertiesButton->setIconSize(QSize(32,32));
ui->actionItem_Properties->setIcon(QIcon("../NoteBinder/Icons/ItemPropertiesIcon.png"));
ui->actionHelp->setIcon(QIcon("../NoteBinder/Icons/HelpIcon.png"));
/* Load Application Settings */
QString defaultSettingsPath = QDir().homePath() + "/.config/notebinder/settings.conf";
// Default Settings for the General Settings, which cannot be modified unlike the files in .config
// This determines where the configuration file is located and if it doesn't exist, it creates it.
QString defaultSetting_defaultNotebookPath = QDir().homePath() + "/Documents";
// Default Path to Save Notebooks (the File Dialog will first open up to this directory).
// Default Path is $HOME/Documents where $HOME is the default home directory for the user running this program.
QString defaultSetting_defaultGenSettingsPath = QDir().homePath() + "/.config/notebinder/general.conf";
// Default Path to save the general setting information (settings like these three variables)
QString defaultSetting_defaultAppLauncherPath = QDir().homePath() + "/.config/notebinder/applauncher.conf";
// Default Path to save the application launcher setting information
QString defaultSetting_defualtNotebookListPath = QDir().homePath() + "/.config/notebinder/notebooklist.conf";
// List of Notebooks that have been opened in the last instance. This will open existing Notebooks.
int defaultSetting_hideDirectoryChecked = 0; // Defaults to Showing Directory Column on Notebook List
int defaultSetting_hideSizeChecked = 0; // Defaults to Showing Size Column on NotebookList
int defaultSetting_iconSize = 32; // Default Size of Notebook and Content Icons
QList<ApplicationLaunchers*> applicationLaunchers;
QFile file_defaultSettings(defaultSettingsPath);
QFileInfo file_defaultSettings_Info(file_defaultSettings);
QStringList strings_defaultSettings;
if(!file_defaultSettings_Info.absoluteDir().exists())
{
QDir().mkdir(file_defaultSettings_Info.absoluteDir().path());
}
if(!file_defaultSettings.exists())
{
// If Default Settings File does not exist:
if (file_defaultSettings.open(QIODevice::ReadWrite)) {
QTextStream in(&file_defaultSettings);
in << "GeneralSettings_ConfigFile: " << defaultSetting_defaultGenSettingsPath << "\n";
}
strings_defaultSettings.append("GeneralSettings_ConfigFile: ");
strings_defaultSettings.append(defaultSetting_defaultGenSettingsPath);
file_defaultSettings.close();
} else {
// Read from Existing Default Settings File:
if (file_defaultSettings.open(QIODevice::ReadOnly)) {
QTextStream in(&file_defaultSettings);
while (!in.atEnd()) {
strings_defaultSettings += in.readLine().split(" ");
}
}
file_defaultSettings.close();
}
// Check the General Settings
QFile file_generalSettings(strings_defaultSettings.at(1));
QFileInfo file_generalSettings_Info(file_generalSettings);
QStringList strings_generalSettings;
if(!file_generalSettings_Info.absoluteDir().exists())
{
QDir().mkdir(file_generalSettings_Info.absoluteDir().path());
}
if(!file_generalSettings.exists())
{
// If Default Settings File does not exist:
if (file_generalSettings.open(QIODevice::ReadWrite)) {
QTextStream in(&file_generalSettings);
in << "DefaultNotebookPath: " << defaultSetting_defaultNotebookPath << "\n"
<< "DefaultAppLauncherPath: " << defaultSetting_defaultAppLauncherPath << "\n"
<< "DefaultNotebookListPath: " << defaultSetting_defualtNotebookListPath << "\n"
<< "HideDirectoryChecked: " << QString::number(defaultSetting_hideDirectoryChecked) << "\n"
<< "HideSizeChecked: " << QString::number(defaultSetting_hideSizeChecked) << "\n"
<< "IconSize: " << QString::number(defaultSetting_iconSize);
}
strings_generalSettings.append("DefaultNotebookPath: ");
strings_generalSettings.append(defaultSetting_defaultNotebookPath);
strings_generalSettings.append("DefaultAppLauncherPath: ");
strings_generalSettings.append(defaultSetting_defaultAppLauncherPath);
strings_generalSettings.append("DefaultNotebookListPath: ");
strings_generalSettings.append(defaultSetting_defualtNotebookListPath);
strings_generalSettings.append("HideDirectoryChecked: ");
strings_generalSettings.append(QString::number(defaultSetting_hideDirectoryChecked));
strings_generalSettings.append("HideSizeChecked: ");
strings_generalSettings.append(QString::number(defaultSetting_hideSizeChecked));
strings_generalSettings.append("IconSize: ");
strings_generalSettings.append(QString::number(defaultSetting_iconSize));
file_generalSettings.close();
} else {
// Read from Existing Default Settings File:
if (file_generalSettings.open(QIODevice::ReadOnly)) {
QTextStream in(&file_generalSettings);
while (!in.atEnd()) {
strings_generalSettings += in.readLine().split(" ");
}
}
file_generalSettings.close();
}
// Check Application Launcher Settings
// If there is no existing Application Launcher Settings
QFile file_applicationLauncher(strings_generalSettings.at(3));
QFileInfo file_applicationLauncher_Info(file_applicationLauncher);
QStringList strings_applicationLauncher;
if(!file_applicationLauncher_Info.absoluteDir().exists())
{
QDir().mkdir(file_applicationLauncher_Info.absoluteDir().path());
}
int line_num = 0;
if(file_applicationLauncher.exists())
{
// Read from Existing Default Settings File:
if (file_applicationLauncher.open(QIODevice::ReadOnly)) {
QTextStream in(&file_applicationLauncher);
while (!in.atEnd()) {
strings_applicationLauncher += in.readLine();
line_num++;
}
}
file_applicationLauncher.close();
}
if(!strings_applicationLauncher.isEmpty())
{
QString applicationName;
QStringList applicationExtensions;
QString applicationLocation;
int line_idx = 0;
for(line_idx = 0; line_idx < line_num; line_idx++)
{
applicationName = strings_applicationLauncher.at(line_idx).split(" ").at(0);
applicationExtensions = strings_applicationLauncher.at(line_idx).split(" ").at(1).split(",");
applicationLocation = strings_applicationLauncher.at(line_idx).split(" ").at(2);
ApplicationLaunchers* applauncher = new ApplicationLaunchers();
applauncher->setApplicationName(applicationName);
applauncher->setApplicationExtension(applicationExtensions);
applauncher->setApplicationLocation(applicationLocation);
applicationLaunchers.append(applauncher);
}
}
// Check List of Notebooks Opened from Previous Instance.
QFile file_NotebookList(strings_generalSettings.at(5));
QFileInfo file_NotebookList_Info(file_NotebookList);
QStringList strings_notebooklist;
if(!file_NotebookList_Info.absoluteDir().exists())
{
QDir().mkdir(file_NotebookList_Info.absoluteDir().path());
}
line_num = 0; // Restart counter for different file.
if(file_NotebookList.exists())
{
// Read from Existing Default Settings File:
if (file_NotebookList.open(QIODevice::ReadOnly)) {
QTextStream in(&file_NotebookList);
while (!in.atEnd()) {
strings_notebooklist += in.readLine();
line_num++;
}
}
file_NotebookList.close();
}
if(!strings_notebooklist.isEmpty())
{
int line_idx = 0;
for(line_idx = 0; line_idx < line_num; line_idx++)
{
QString notebookFile = strings_notebooklist.at(line_idx);
if(QFileInfo::exists(notebookFile))
{
Notebook* notebook = OpenNotebook(notebookFile);
if(notebook != nullptr)
{
notebookList.nbList.append(notebook);
}
}
}
}
uiSettings = new Settings(strings_generalSettings.at(1), strings_generalSettings.at(5),
strings_defaultSettings.at(1), strings_generalSettings.at(3),
applicationLaunchers, 0, this);
if(strings_generalSettings.at(7).toInt() == 0)
{
// Unchecked
ui->hideDirectory_Check->setCheckState(Qt::CheckState::Unchecked);
} else {
// Checked
ui->hideDirectory_Check->setCheckState(Qt::CheckState::Checked);
}
if(strings_generalSettings.at(9).toInt() == 0)
{
// Unchecked
ui->hideSize_Check->setCheckState(Qt::CheckState::Unchecked);
} else {
// Checked
ui->hideSize_Check->setCheckState(Qt::CheckState::Checked);
}
if((strings_generalSettings.at(11).toInt() < 16 || strings_generalSettings.at(11).toInt() > 64) || strings_generalSettings.at(11).isNull())
{
ui->notebookList->setIconSize(QSize(defaultSetting_iconSize, defaultSetting_iconSize));
ui->iconSizeSlider->setValue(defaultSetting_iconSize);
} else {
ui->notebookList->setIconSize(QSize(strings_generalSettings.at(11).toInt(), strings_generalSettings.at(11).toInt()));
ui->iconSizeSlider->setValue(strings_generalSettings.at(11).toInt());
}
ui->notebookList->expandAll();
ui->notebookList->sortItems(0, Qt::SortOrder::AscendingOrder);
}
void MainWindow::ExitProgram()
{
/* Save Notebooks Opened for another Session */
QStringList notebooksOpened;
int idx = 0;
for(idx = 0; idx < notebookList.nbList.size(); idx++)
{
notebooksOpened.append(notebookList.nbList.at(idx)->location + QDir::separator() + "notebook.noteb");
}
QFile file_notebooksOpened(uiSettings->getOpenedNotebookList());
idx = 0;
if(file_notebooksOpened.exists())
{
file_notebooksOpened.remove();
}
if (file_notebooksOpened.open(QIODevice::ReadWrite)) {
QTextStream in(&file_notebooksOpened);
for(idx = 0; idx < notebooksOpened.size(); idx++)
{
if(idx == notebooksOpened.size() - 1)
{
in << notebooksOpened.at(idx);
} else {
in << notebooksOpened.at(idx) << "\n";
}
}
}
file_notebooksOpened.close();
/* Save Default Configuration Settings */
QFile file_defaultSettings(QDir().homePath() + "/.config/notebinder/settings.conf");
if(file_defaultSettings.exists())
{
file_defaultSettings.remove();
}
if(file_defaultSettings.open(QIODevice::ReadWrite)) {
QTextStream in(&file_defaultSettings);
in << "GeneralSettings_ConfigFile: " << uiSettings->getGeneralSettingsConfigFile();
}
file_defaultSettings.close();
/* Save General Settings */
QFile file_generalSettings(uiSettings->getGeneralSettingsConfigFile());
if(file_generalSettings.exists())
{
file_generalSettings.remove();
}
if(file_generalSettings.open(QIODevice::ReadWrite)) {
QTextStream in(&file_generalSettings);
in << "DefaultNotebookPath: " << uiSettings->getDefaultNotebookPath() << "\n"
<< "DefaultAppLauncherPath: " << uiSettings->getApplicationLauncherConfigFile() << "\n"
<< "DefaultNotebookListPath: " << uiSettings->getOpenedNotebookList() << "\n"
<< "HideDirectoryChecked: " << QString::number(ui->hideDirectory_Check->checkState()) << "\n"
<< "HideSizeChecked: " << QString::number(ui->hideSize_Check->checkState()) << "\n"
<< "IconSize: " << QString::number(ui->iconSizeSlider->value());
}
file_generalSettings.close();
/* Save Application Launchers */
QFile file_applicationLaunchers(uiSettings->getApplicationLauncherConfigFile());
int line_num = 0;
if(file_applicationLaunchers.exists())
{
file_applicationLaunchers.remove();
}
if(file_applicationLaunchers.open(QIODevice::ReadWrite)) {
QTextStream in(&file_applicationLaunchers);
for(line_num = 0; line_num < uiSettings->applicationLaunchers.size(); line_num++)
{
in << uiSettings->applicationLaunchers.at(line_num)->getApplicationName() << " ";
int extension_idx = 0;
for(extension_idx = 0; extension_idx < uiSettings->applicationLaunchers.at(line_num)->getApplicationExtensions().size(); extension_idx++)
{
if(extension_idx == uiSettings->applicationLaunchers.at(line_num)->getApplicationExtensions().size() - 1)
{
in << uiSettings->applicationLaunchers.at(line_num)->getSingleApplicationExtension(extension_idx) << " ";
} else {
in << uiSettings->applicationLaunchers.at(line_num)->getSingleApplicationExtension(extension_idx) << ",";
}
}
in << uiSettings->applicationLaunchers.at(line_num)->getApplicationLocation() << "\n";
}
}
file_applicationLaunchers.close();
}
/* Tasks to run after exiting program */
void MainWindow::closeEvent (QCloseEvent *event)
{
ExitProgram();
QApplication::quit();
}
/* Create New Notebook (and Open it) */
void MainWindow::on_newNotebook_Button_clicked()
{
Notebook* notebook = NewNotebook(notebookList.nbList);
if(notebook != nullptr)
{
ui->notebookList->insertTopLevelItem(0, notebookList.createNotebookIcon(notebook));
notebookList.addNotebookToList(notebook);
}
}
/* Open Existing Notebook */
void MainWindow::on_openNotebook_Button_clicked()
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(tr("Notebook File (*.noteb)"));
QString fileName = dialog.getOpenFileName(this, tr("Open File"), uiSettings->getDefaultNotebookPath(), tr("Notebook File (*.noteb)")); // Open Dialog
Notebook* notebook;
bool notebook_opened = false;
int nb_idx = 0;
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(fileName == (notebookList.nbList.at(nb_idx)->location + QDir::separator() + "notebook.noteb"))
{
notebook_opened = true; // Notebook Already Exists in that spot, don't recreate it!
}
}
if(notebook_opened == false)
{
notebook = OpenNotebook(fileName);
} else {
notebook = nullptr; // Notebook already Exists so do not reopen it!
}
if(notebook != nullptr)
{
notebookList.addNotebookToList(notebook);
}
}
Notebook* MainWindow::OpenNotebook(QString fileName)
{
QFileInfo notebookFileInfo(fileName); // Notebook File Information
if (fileName.isNull() == false)
{
QFileInfo notebookDirInfo(notebookFileInfo.path());
QString fileDir = notebookFileInfo.absoluteDir().path(); // Directory Path of Notebook
Notebook *notebook = new Notebook();
*notebook = openNotebook(fileDir); // Create New Notebook
QTreeWidgetItem* notebookNameItem = notebookList.createNotebookIcon(notebook);
ui->notebookList->insertTopLevelItem(0, notebookNameItem); // Notebook is Opened, next to open it's contents.
int idx = 0; // File Index (including Directory)
int dir_idx = 0; // Directory Index
for(idx = 0; idx < notebook->files.size(); idx++)
{
QFileInfo fileInfo(notebook->files.at(idx));
if(fileInfo.fileName() != "." && fileInfo.fileName() != ".." && fileInfo.fileName().endsWith(".noteb") == false && fileInfo.fileName().endsWith("~") == false)
// Exclude files that contain notebook information, parent and current directory and any files ending with a ~ indicating a backup file. We will not be counting those.
{
if(fileInfo.isFile() == true)
{
// Section
notebookNameItem->addChild(notebookList.createSectionIcon(fileInfo));
} else {
// Section Group
SectionGroup* sectionGroup = new SectionGroup();
*sectionGroup = openSectionGroup(notebook->name, notebook->files.at(idx));
QTreeWidgetItem* sectionGroupItem = notebookList.createSectionGroupIcon(sectionGroup);
notebookNameItem->addChild(sectionGroupItem);
openNotebookDirSequence_treeWidget(sectionGroup, sectionGroupItem);
notebook->sectionGroupArray.append(sectionGroup);
dir_idx++;
}
}
}
return notebook;
} else {
return nullptr;
}
}
/* Create New Section for a Notebook or Section Group */
void MainWindow::on_newSection_Button_clicked()
{
NewSection();
}
void MainWindow::NewSection()
{
int nb_idx = 0;
int sg_idx = 0;
int item_level = 0;
QStringList list;
QStringList* notebookColorList = new QStringList();
QStringList* notebookDirList = new QStringList();
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(nb_idx == 0)
{
item_level++;
}
notebookColorList->append(notebookList.nbList.at(nb_idx)->color);
notebookDirList->append(notebookList.nbList.at(nb_idx)->location);
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
if(sg_idx == 0)
{
item_level++;
}
notebookColorList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->color);
notebookDirList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location);
item_level = newSectionDirSequence_toSectToDirDialog(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), notebookColorList, notebookDirList, item_level, 1);
}
}
list = addItemsToDirectorySelection(notebookList.nbList);
newSectionDialog* uiNewSectionDialog = new newSectionDialog(*notebookColorList, *notebookDirList, list, uiSettings->applicationLaunchers);
if(!uiNewSectionDialog->exec()) return;
QString fullFileName = uiNewSectionDialog->getFullFileName();
runNewSectionApplication(fullFileName);
QFileInfo newFileInfo(fullFileName);
QTreeWidgetItem* item = notebookList.createSectionIcon(newFileInfo);
QList<QTreeWidgetItem*> clist = ui->notebookList->findItems(newFileInfo.fileName(), Qt::MatchContains|Qt::MatchRecursive, 0);
foreach(QTreeWidgetItem* items, clist)
{
items->addChild(item);
}
UpdateNotebookList();
}
void MainWindow::runNewSectionApplication(QString fileLocation)
{
QFileInfo fileInfo(fileLocation);
if(fileInfo.exists() == false)
{
QString appExtension = "." + fileInfo.suffix();
int appLauncher_idx = 0; // Count up to the Total Number of Applicaiton Launchers available
for(appLauncher_idx = 0; appLauncher_idx < uiSettings->applicationLaunchers.size(); appLauncher_idx++)
{
int extensions_idx = 0; // Count up to the Total Number of Extensions in all file Launchers
for(extensions_idx = 0; extensions_idx < uiSettings->applicationLaunchers.at(appLauncher_idx)->getApplicationExtensions().size(); extensions_idx++)
{
if(uiSettings->applicationLaunchers.at(appLauncher_idx)->getSingleApplicationExtension(extensions_idx) == appExtension)
{
QObject *parent = new QObject();
QString program = uiSettings->applicationLaunchers.at(appLauncher_idx)->getApplicationLocation();
QStringList arguments; // No Additional Arguments besides File Location
arguments.append(fileLocation);
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments, QIODevice::ReadWrite);
}
}
}
} else {
QMessageBox messageBox;
QString s_txt = fileInfo.fileName();
QFont fontSize;
fontSize.setPointSize(12);
// Dialog Opens Asking for confirmation if you want to delete either a Notebook, Section Group or Section.
messageBox.setWindowTitle("File Already Exists!");
messageBox.setFont(fontSize);
messageBox.setText("Are you sure you want to overwrite " + s_txt + "?");
messageBox.setStandardButtons(QMessageBox::Yes);
messageBox.addButton(QMessageBox::No);
messageBox.setDefaultButton(QMessageBox::No);
if(messageBox.exec() == QMessageBox::Yes)
{
QString appExtension = "." + fileInfo.suffix();
int appLauncher_idx = 0; // Count up to the Total Number of Applicaiton Launchers available
for(appLauncher_idx = 0; appLauncher_idx < uiSettings->applicationLaunchers.size(); appLauncher_idx++)
{
int extensions_idx = 0; // Count up to the Total Number of Extensions in all file Launchers
for(extensions_idx = 0; extensions_idx < uiSettings->applicationLaunchers.at(appLauncher_idx)->getApplicationExtensions().size(); extensions_idx++)
{
if(uiSettings->applicationLaunchers.at(appLauncher_idx)->getSingleApplicationExtension(extensions_idx) == appExtension)
{
QObject *parent = new QObject();
QString program = uiSettings->applicationLaunchers.at(appLauncher_idx)->getApplicationLocation();
QStringList arguments; // No Additional Arguments besides File Location
arguments.append(fileLocation);
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments, QIODevice::ReadWrite);
}
}
}
}
}
}
/* Open Highlighted Section */
void MainWindow::on_openSection_Button_clicked()
{
OpenSection();
}
void MainWindow::OpenSection()
{
QTreeWidgetItem* selectedItem = ui->notebookList->currentItem();
QString selectedItemStr = selectedItem->text(1);
/* Searching for File within List of Notebooks */
runOpenSectionApplication(selectedItemStr);
}
void MainWindow::runOpenSectionApplication(QString fileLocation)
{
QFileInfo fileInfo(fileLocation);
if(fileInfo.exists() == true)
{
QString appExtension = "." + fileInfo.suffix();
int appLauncher_idx = 0; // Count up to the Total Number of Application Launchers available
for(appLauncher_idx = 0; appLauncher_idx < uiSettings->applicationLaunchers.size(); appLauncher_idx++)
{
int extensions_idx = 0; // Count up to the Total Number of Extensions in all file Launchers
for(extensions_idx = 0; extensions_idx < uiSettings->applicationLaunchers.at(appLauncher_idx)->getApplicationExtensions().size(); extensions_idx++)
{
if(uiSettings->applicationLaunchers.at(appLauncher_idx)->getSingleApplicationExtension(extensions_idx) == appExtension)
{
QObject *parent = new QObject();
QString program = uiSettings->applicationLaunchers.at(appLauncher_idx)->getApplicationLocation();
QStringList arguments; // No Additional Arguments besides File Location
arguments.append(fileLocation);
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments, QIODevice::ReadWrite);
}
}
}
} else {
QMessageBox messageBox;
QFont fontSize;
fontSize.setPointSize(12);
messageBox.setWindowTitle("Error");
messageBox.setFont(fontSize);
messageBox.setText("This file Does Not Exist!");
messageBox.exec();
}
}
/* Create New Section Group */
void MainWindow::on_newSectionGroup_Button_clicked()
{
NewSectionGroup();
}
void MainWindow::NewSectionGroup()
{
int nb_idx = 0;
int sg_idx = 0;
int item_level = 0;
QStringList list;
QStringList* notebookColorList = new QStringList();
QStringList* notebookDirList = new QStringList();
QList<QIcon*> iconList;
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(nb_idx == 0)
{
item_level++; // Parent is Notebook
}
notebookDirList->append(notebookList.nbList.at(nb_idx)->location);
notebookColorList->append(notebookList.nbList.at(nb_idx)->color);
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
if(sg_idx == 0)
{
item_level++; // Parent is SectionGroup
}
notebookDirList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location);
notebookColorList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->color);
item_level = newSectionDirSequence_toSectToDirDialog(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), notebookColorList, notebookDirList, item_level, 1);
}
}
list = addItemsToDirectorySelection(notebookList.nbList);
newSectionGroupDialog* uiNewSectionGroupDialog = new newSectionGroupDialog(*notebookColorList, *notebookDirList, list);
if(!uiNewSectionGroupDialog->exec()) return;
if(uiNewSectionGroupDialog->getSgName() != "")
{
SectionGroup* sectionGroup = new SectionGroup();
sectionGroup->name = uiNewSectionGroupDialog->getSgName();
sectionGroup->location = uiNewSectionGroupDialog->getSgDirectory();
sectionGroup->color = uiNewSectionGroupDialog->getSgColor();
QFileInfo fileInfo(sectionGroup->location);
sectionGroup->parentDir = fileInfo.path();
QString sectionGroupFile = sectionGroup->location + QDir::separator() + "sectiongroup.sectgr";
QFile file(sectionGroupFile);
if (file.open(QIODevice::ReadWrite)) {
QTextStream in(&file);
in << sectionGroup->name << "\n" << sectionGroup->color << "\n";
}
file.close();
nb_idx = 0;
sg_idx = 0;
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(sectionGroup->parentDir == notebookList.nbList.at(nb_idx)->location)
{
notebookList.nbList.at(nb_idx)->files.append(sectionGroup->location);
notebookList.nbList.at(nb_idx)->sectionGroupArray.append(sectionGroup);
}
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
newSectionDirSequence_toSectToDirDialog(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), sectionGroup);
if(sectionGroup->parentDir == notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location)
{
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.append(sectionGroup->location);
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->sectionGroupArray.append(sectionGroup);
}
}
}
QFileInfo parentDirInfo(sectionGroup->parentDir);
QTreeWidgetItem* sectionGroupItem = notebookList.createSectionGroupIcon(sectionGroup);
QList<QTreeWidgetItem*> clist = ui->notebookList->findItems(parentDirInfo.absoluteFilePath(), Qt::MatchContains|Qt::MatchRecursive, 1);
foreach(QTreeWidgetItem* item, clist)
{
item->addChild(sectionGroupItem);
}
UpdateNotebookList();
}
}
void MainWindow::on_generalSettings_Button_clicked()
{
uiSettings->setSettingsTabPage(0);
if(!uiSettings->exec()) return;
}
/* Close Selected Notebook */
void MainWindow::on_closeNotebook_Button_clicked()
{
CloseNotebook();
}
void MainWindow::CloseNotebook()
{
int nb_idx = 0;
QTreeWidgetItem* selectedItem = ui->notebookList->currentItem();
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(notebookList.nbList.at(nb_idx)->location == selectedItem->text(1))
{
notebookList.nbList.removeAt(nb_idx);
delete selectedItem;
}
}
}
void MainWindow::on_closeAllNotebooksButton_clicked()
{
CloseAllNotebooks();
}
void MainWindow::CloseAllNotebooks()
{
int nb_idx = 0;
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
QTreeWidgetItem* selectedItem = ui->notebookList->currentItem();
delete selectedItem;
}
notebookList.nbList.clear();
}
/* Delete Selected Item*/
void MainWindow::on_deleteSelectedItem_Button_clicked()
{
QMessageBox messageBox;
QTreeWidgetItem* selectedItem = ui->notebookList->currentItem();
QString s_txt;
QFont fontSize;
fontSize.setPointSize(12);
s_txt = selectedItem->text(0);
// Dialog Opens Asking for confirmation if you want to delete either a Notebook, Section Group or Section.
messageBox.setWindowTitle("Delete Selected Item");
messageBox.setFont(fontSize);
messageBox.setText("Are you sure you want to delete " + s_txt + "?");
messageBox.setStandardButtons(QMessageBox::Yes);
messageBox.addButton(QMessageBox::No);
messageBox.setDefaultButton(QMessageBox::No);
if(messageBox.exec() == QMessageBox::Yes)
{
DeleteSelectedItem(selectedItem);
UpdateNotebookList();
}
}
void MainWindow::DeleteSelectedItem(QTreeWidgetItem* selectedItem)
{
QString itemLocation = selectedItem->text(1);
int nb_idx = 0;
int file_idx = 0;
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(notebookList.nbList.at(nb_idx)->location == itemLocation)
{
notebookList.nbList.removeAt(nb_idx);
} else {
for(file_idx = 0; file_idx < notebookList.nbList.at(nb_idx)->files.size(); file_idx++)
{
if(notebookList.nbList.at(nb_idx)->files.at(file_idx) == itemLocation)
{
QFileInfo fileInfo(notebookList.nbList.at(nb_idx)->files.at(file_idx));
if(fileInfo.isDir())
{
int sg2_idx = 0;
for(sg2_idx = 0; sg2_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg2_idx++)
{
if(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg2_idx)->location == itemLocation)
{
notebookList.nbList.at(nb_idx)->sectionGroupArray.removeAt(sg2_idx);
}
}
}
notebookList.nbList.at(nb_idx)->files.removeAt(file_idx);
} else {
QFileInfo fileInfo(notebookList.nbList.at(nb_idx)->files.at(file_idx));
if(fileInfo.isDir())
{
int sg_idx = 0;
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
// Section Group
deleteNotebookDirSequence_findFile(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), itemLocation);
}
}
}
}
}
file_idx = 0;
}
// Remove File if it exists.
if(QFile(itemLocation).exists())
{
QFileInfo nbfileInfo(itemLocation);
if(nbfileInfo.isFile())
{
QFile file(itemLocation);
file.moveToTrash();
} else {
QDir dir(itemLocation);
if(dir.exists(itemLocation))
{
dir.removeRecursively();
}
}
}
}
/* Item Properties */
void MainWindow::on_itemPropertiesButton_clicked()
{
if(ui->notebookList->currentItem() != nullptr)
{
QString selectedItem = ui->notebookList->currentItem()->text(1);
itemProperties* uiItemProperties = new itemProperties(&notebookList, selectedItem);
if(!uiItemProperties->exec()) return;
UpdateNotebookList();
}
}
/* Import Section */
void MainWindow::on_importSection_Button_clicked()
{
int nb_idx = 0;
int sg_idx = 0;
int item_level = 0;
QStringList list;
QStringList* notebookDirList = new QStringList();
QStringList* notebookColorList = new QStringList();
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(nb_idx == 0)
{
item_level++;
}
notebookDirList->append(notebookList.nbList.at(nb_idx)->location);
notebookColorList->append(notebookList.nbList.at(nb_idx)->color);
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
if(sg_idx == 0)
{
item_level++;
}
notebookDirList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location);
notebookColorList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->color);
item_level = newSectionDirSequence_toSectToDirDialog(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), notebookColorList, notebookDirList, item_level, 1);
}
}
list = addItemsToDirectorySelection(notebookList.nbList);
importSection* uiImportSection = new importSection(*notebookColorList, *notebookDirList, list);
if(!uiImportSection->exec()) return;
QString fullFileName = uiImportSection->getNewFile();
QFileInfo newFileInfo(fullFileName);
QTreeWidgetItem* sectionItem = notebookList.createSectionIcon(newFileInfo);
QList<QTreeWidgetItem*> clist = ui->notebookList->findItems(newFileInfo.absoluteFilePath(), Qt::MatchContains|Qt::MatchRecursive, 1);
foreach(QTreeWidgetItem* item, clist)
{
item->addChild(sectionItem);
}
nb_idx = 0;
int file_idx = 0;
sg_idx = 0;
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
QFileInfo notebookFileInfo(notebookList.nbList.at(nb_idx)->location);
if(notebookList.nbList.at(nb_idx)->location == newFileInfo.absolutePath())
{
if(!notebookList.nbList.at(nb_idx)->files.contains(fullFileName))
{
notebookList.nbList.at(nb_idx)->files.append(fullFileName);
}
}
for(file_idx = 0; file_idx < notebookList.nbList.at(nb_idx)->files.size(); file_idx++)
{
QFileInfo fileInfo(notebookList.nbList.at(nb_idx)->files.at(file_idx));
if(!fileInfo.isFile())
{
// Section Group
if(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location == fileInfo.absolutePath())
{
if(!notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.contains(fullFileName))
{
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.append(fullFileName);
}
} else {
newSectionDirSequence_fileToSectGr(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), fullFileName);
}
sg_idx++;
}
}
file_idx = 0;
sg_idx = 0;
}
UpdateNotebookList();
}
/* Export Section */
void MainWindow::on_exportSection_Button_clicked()
{
QTreeWidgetItem* selectedItem = ui->notebookList->currentItem();
QString fileSelected = selectedItem->text(1);
QFile file(fileSelected);
QFileInfo fileInfo(fileSelected);
if(fileInfo.isFile())
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilter(tr("Any File"));
QString fileName = dialog.getSaveFileName(this, tr("Save File"), QDir().homePath() + QDir::separator()
+ "Documents" + QDir::separator() + fileInfo.fileName(), tr("File")); // Open Dialog
file.copy(fileName);
}
}
/* Move Item */
void MainWindow::on_moveItem_Button_clicked()
{
QTreeWidgetItem* currentItem = ui->notebookList->currentItem();
if(currentItem != nullptr)
{
QTreeWidgetItem* parentItem = ui->notebookList->currentItem()->parent();
if(parentItem != nullptr)
{
bool moveItemState = true;
QString fileName = ui->notebookList->currentItem()->text(0);
QString fileLocation = ui->notebookList->currentItem()->text(1);
int nb_idx = 0;
int sg_idx = 0;
int item_level = 0;
QStringList list;
QStringList* notebookColorList = new QStringList();
QStringList* notebookDirList = new QStringList();
notebookColorList->empty();
notebookDirList->empty();
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(nb_idx == 0)
{
item_level++;
}
notebookColorList->append(notebookList.nbList.at(nb_idx)->color);
notebookDirList->append(notebookList.nbList.at(nb_idx)->location);
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
if(sg_idx == 0)
{
item_level++;
}
notebookColorList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->color);
notebookDirList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location);
item_level = newSectionDirSequence_toSectToDirDialog(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), notebookColorList, notebookDirList, item_level, 1);
}
}
list = addItemsToDirectorySelection(notebookList.nbList);
CopyItemDialog* uiCopyItemDialog = new CopyItemDialog(moveItemState, *notebookColorList, *notebookDirList, list, fileName, fileLocation);
if(!uiCopyItemDialog->exec()) return;
if(uiCopyItemDialog->Accepted)
{
DeleteSelectedItem(currentItem);
QString fullFileName = uiCopyItemDialog->getFileLocation();
QFileInfo newFileInfo(fullFileName);
nb_idx = 0;
sg_idx = 0;
if(newFileInfo.isFile())
{
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(!notebookList.nbList.at(nb_idx)->files.contains(fullFileName) && (newFileInfo.absolutePath() == notebookList.nbList.at(nb_idx)->location))
{
notebookList.nbList.at(nb_idx)->files.append(fullFileName);
}
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
if(!notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.contains(fullFileName)
&& (newFileInfo.absolutePath() == notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location))
{
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.append(fullFileName);
}
newSectionDirSequence_fileToSectGr(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), fullFileName);
}
}
} else {
SectionGroup* sectionGroup = new SectionGroup();
*sectionGroup = openSectionGroup(newFileInfo.absolutePath(), fullFileName);
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(sectionGroup->parentDir == notebookList.nbList.at(nb_idx)->location)
{
notebookList.nbList.at(nb_idx)->files.append(sectionGroup->location);
notebookList.nbList.at(nb_idx)->sectionGroupArray.append(sectionGroup);
}
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
newSectionDirSequence_toSectToDirDialog(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), sectionGroup);
if(sectionGroup->parentDir == notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location)
{
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.append(sectionGroup->location);
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->sectionGroupArray.append(sectionGroup);
}
}
}
}
UpdateNotebookList();
}
} else {
messageBox("Error", "Cannot Copy Notebooks within themselves!");
}
} else {
messageBox("Error", "Must Select a Valid Item!");
}
}
/* Copy Item */
void MainWindow::on_copyItem_Button_clicked()
{
QTreeWidgetItem* currentItem = ui->notebookList->currentItem();
if(currentItem != nullptr)
{
QTreeWidgetItem* parentItem = ui->notebookList->currentItem()->parent();
if(parentItem != nullptr)
{
bool moveItemState = false;
QString fileName = ui->notebookList->currentItem()->text(0);
QString fileLocation = ui->notebookList->currentItem()->text(1);
int nb_idx = 0;
int sg_idx = 0;
int item_level = 0;
QStringList list;
QStringList* notebookColorList = new QStringList();
QStringList* notebookDirList = new QStringList();
notebookColorList->empty();
notebookDirList->empty();
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(nb_idx == 0)
{
item_level++;
}
notebookColorList->append(notebookList.nbList.at(nb_idx)->color);
notebookDirList->append(notebookList.nbList.at(nb_idx)->location);
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
if(sg_idx == 0)
{
item_level++;
}
notebookColorList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->color);
notebookDirList->append(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location);
item_level = newSectionDirSequence_toSectToDirDialog(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), notebookColorList, notebookDirList, item_level, 1);
}
}
list = addItemsToDirectorySelection(notebookList.nbList);
CopyItemDialog* uiCopyItemDialog = new CopyItemDialog(moveItemState, *notebookColorList, *notebookDirList, list, fileName, fileLocation);
if(!uiCopyItemDialog->exec()) return;
if(uiCopyItemDialog->Accepted)
{
QString fullFileName = uiCopyItemDialog->getFileLocation();
QFileInfo newFileInfo(fullFileName);
nb_idx = 0;
sg_idx = 0;
if(newFileInfo.isFile())
{
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(!notebookList.nbList.at(nb_idx)->files.contains(fullFileName) && (newFileInfo.absolutePath() == notebookList.nbList.at(nb_idx)->location))
{
notebookList.nbList.at(nb_idx)->files.append(fullFileName);
}
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
if(!notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.contains(fullFileName)
&& (newFileInfo.absolutePath() == notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location))
{
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.append(fullFileName);
}
newSectionDirSequence_fileToSectGr(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), fullFileName);
}
}
} else {
SectionGroup* sectionGroup = new SectionGroup();
*sectionGroup = openSectionGroup(newFileInfo.absolutePath(), fullFileName);
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
if(sectionGroup->parentDir == notebookList.nbList.at(nb_idx)->location)
{
notebookList.nbList.at(nb_idx)->files.append(sectionGroup->location);
notebookList.nbList.at(nb_idx)->sectionGroupArray.append(sectionGroup);
}
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
newSectionDirSequence_toSectToDirDialog(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), sectionGroup);
if(sectionGroup->parentDir == notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location)
{
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.append(sectionGroup->location);
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->sectionGroupArray.append(sectionGroup);
}
}
}
}
UpdateNotebookList();
}
} else {
messageBox("Error", "Cannot Copy Notebooks within themselves!");
}
} else {
messageBox("Error", "Must Select a Valid Item!");
}
}
/* Hide Directory and Size Check Boxes */
void MainWindow::on_hideDirectory_Check_stateChanged(int arg1)
{
if(arg1 == 0)
{
// Unchecked
ui->notebookList->showColumn(1);
} else {
// Checked
ui->notebookList->hideColumn(1);
}
}
void MainWindow::on_hideSize_Check_stateChanged(int arg1)
{
if(arg1 == 0)
{
// Unchecked
ui->notebookList->showColumn(2);
} else {
// Checked
ui->notebookList->hideColumn(2);
}
}
void MainWindow::on_refreshNotebookListButton_clicked()
{
UpdateNotebookList();
UpdateNotebookList(); // Refresh two times in a row for better consistency. Especially if the file names have been changed via file manager
}
/* Update The Notebook List (QTreeWidget) */
void MainWindow::UpdateNotebookList()
{
int nb_idx = 0;
int sg_idx = 0;
int file_idx = 0;
// Empty Current List and Update List
ui->notebookList->clear();
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
QFileInfo nbFileInfo(notebookList.nbList.at(nb_idx)->location);
QDir directory(notebookList.nbList.at(nb_idx)->location);
directory.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
foreach(QFileInfo fileInfo, directory.entryInfoList())
{
if(!notebookList.nbList.at(nb_idx)->files.contains(fileInfo.absoluteFilePath()) && !fileInfo.fileName().endsWith(".noteb")
&& fileInfo.fileName() != "." && fileInfo.fileName() != ".." && !fileInfo.fileName().endsWith("~"))
{
notebookList.nbList.at(nb_idx)->files.append(fileInfo.absoluteFilePath());
}
}
file_idx = 0;
for(sg_idx = 0; sg_idx < notebookList.nbList.at(nb_idx)->sectionGroupArray.size(); sg_idx++)
{
QFileInfo sgFileInfo(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location);
QDir directory(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->location);
directory.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
foreach(QFileInfo fileInfo, directory.entryInfoList())
{
if(!notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.contains(fileInfo.absoluteFilePath()) && !fileInfo.fileName().endsWith(".sectgr")
&& fileInfo.fileName() != "." && fileInfo.fileName() != ".." && !fileInfo.fileName().endsWith("~"))
{
notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx)->files.append(fileInfo.absoluteFilePath());
}
}
updateNotebookDirSequence_fileToSecGr(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx));
}
sg_idx = 0;
}
nb_idx = 0;
file_idx = 0;
sg_idx = 0;
for(nb_idx = 0; nb_idx < notebookList.nbList.size(); nb_idx++)
{
QFileInfo notebookFileInfo(notebookList.nbList.at(nb_idx)->location);
QTreeWidgetItem* notebookNameItem = notebookList.createNotebookIcon(notebookList.nbList.at(nb_idx));
for(file_idx = 0; file_idx < notebookList.nbList.at(nb_idx)->files.size(); file_idx++)
{
if(!QFile(notebookList.nbList.at(nb_idx)->files.at(file_idx)).exists())
{
notebookList.nbList.at(nb_idx)->files.removeAt(file_idx);
if(!QDir(notebookList.nbList.at(nb_idx)->files.at(file_idx)).exists())
{
notebookList.nbList.at(nb_idx)->sectionGroupArray.removeAt(sg_idx);
}
} else {
QFileInfo fileInfo(notebookList.nbList.at(nb_idx)->files.at(file_idx));
if(fileInfo.isFile() == true)
{
// Section
notebookNameItem->addChild(notebookList.createSectionIcon(fileInfo));
} else {
// Section Group
QTreeWidgetItem* sectionGroupItem = notebookList.createSectionGroupIcon(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx));
notebookNameItem->addChild(sectionGroupItem);
updateNotebookDirSequence_treeWidget(notebookList.nbList.at(nb_idx)->sectionGroupArray.at(sg_idx), sectionGroupItem);
sg_idx++;
}
}
}
ui->notebookList->addTopLevelItem(notebookNameItem);
sg_idx = 0;
}
ui->notebookList->expandAll();
}
void MainWindow::on_iconSizeSlider_valueChanged(int value)
{
ui->notebookList->setIconSize(QSize(value, value));
}
void MainWindow::messageBox(QString title, QString message)
{
QMessageBox messageBox;
QFont fontSize;
fontSize.setPointSize(12);
messageBox.setWindowTitle(title);
messageBox.setFont(fontSize);
messageBox.setText(message);
messageBox.exec();
}
/* Recursive Functions */
void MainWindow::newSectionDirSequence_fileToSectGr(SectionGroup* sectionGroup, QString fullFileName)
{
int sg_idx = 0;
QFileInfo newFileInfo(fullFileName);
for(sg_idx = 0; sg_idx < sectionGroup->sectionGroupArray.size(); sg_idx++)
{
if(!sectionGroup->sectionGroupArray.at(sg_idx)->files.contains(fullFileName)
&& (newFileInfo.absolutePath() == sectionGroup->sectionGroupArray.at(sg_idx)->location))
{
sectionGroup->sectionGroupArray.at(sg_idx)->files.append(fullFileName);
}
newSectionDirSequence_fileToSectGr(sectionGroup->sectionGroupArray.at(sg_idx), fullFileName);
}
}
void MainWindow::newSectionDirSequence_toSectToDirDialog(SectionGroup* sectionGroup, SectionGroup* subSectionGroup)
{
// This is a Recursive Function
int sg_idx = 0;
for(sg_idx = 0; sg_idx < sectionGroup->sectionGroupArray.size(); sg_idx++)
{
newSectionDirSequence_toSectToDirDialog(sectionGroup->sectionGroupArray.at(sg_idx), subSectionGroup);
if(subSectionGroup->parentDir == sectionGroup->sectionGroupArray.at(sg_idx)->location)
{
sectionGroup->sectionGroupArray.at(sg_idx)->files.append(subSectionGroup->location);
sectionGroup->sectionGroupArray.at(sg_idx)->sectionGroupArray.append(subSectionGroup);
}
}
}
int MainWindow::newSectionDirSequence_toSectToDirDialog(SectionGroup* sectionGroup, QStringList* notebookColorList, QStringList* notebookDirList, int item_level, int tab_count)
{
// This is a Recursive Function
int sg_idx = 0;
int tab_idx = tab_count + 1;
for(sg_idx = 0; sg_idx < sectionGroup->sectionGroupArray.size(); sg_idx++)
{
if(sg_idx == 0)
{
item_level++;
}
notebookDirList->append(sectionGroup->sectionGroupArray.at(sg_idx)->location);
notebookColorList->append(sectionGroup->sectionGroupArray.at(sg_idx)->color);
item_level = newSectionDirSequence_toSectToDirDialog(sectionGroup->sectionGroupArray.at(sg_idx), notebookColorList, notebookDirList, item_level, tab_idx);
}
return item_level;
}
void MainWindow::openNotebookDirSequence_treeWidget(SectionGroup* sectionGroup, QTreeWidgetItem* sectionChildItem)
{
/* This is a Recursive Function */
int idx = 0; // File Index (including Directory)
int dir_idx = 0; // Directory Index
for(idx = 0; idx < sectionGroup->files.size(); idx++)
{
QFileInfo fileInfo(sectionGroup->files.at(idx));
if(fileInfo.fileName() != "." && fileInfo.fileName() != ".." && fileInfo.fileName().endsWith(".sectgr") == false && fileInfo.fileName().endsWith("~") == false)
{
if(fileInfo.isFile() == true)
{
// Section
sectionChildItem->addChild(notebookList.createSectionIcon(fileInfo));
} else {
// Section Group
SectionGroup* subSectionGroup = new SectionGroup();
*subSectionGroup = openSectionGroup(sectionGroup->name, sectionGroup->files.at(idx));
QTreeWidgetItem* subSectionGroupItem = notebookList.createSectionGroupIcon(subSectionGroup);
sectionChildItem->addChild(subSectionGroupItem);
openNotebookDirSequence_treeWidget(subSectionGroup, subSectionGroupItem);
sectionGroup->sectionGroupArray.append(subSectionGroup);
dir_idx++;
}
}
}
sectionGroup->files.sort();
}
void MainWindow::openSectionDirSequence_findFile(SectionGroup* sectionGroup, QString selectedItemStr)
{
/* This is a Recursive Function */
int sg_idx = 0;
int file_sg_idx = 0;
for(sg_idx = 0; sg_idx < sectionGroup->sectionGroupArray.size(); sg_idx++)
{
for(file_sg_idx = 0; file_sg_idx < sectionGroup->sectionGroupArray.at(sg_idx)->files.size(); file_sg_idx++)
{
QFileInfo fileInfo(sectionGroup->sectionGroupArray.at(sg_idx)->files.at(file_sg_idx));
if(selectedItemStr == fileInfo.fileName())
{
// TODO: Implement Application Launcher!
runOpenSectionApplication(sectionGroup->sectionGroupArray.at(sg_idx)->files.at(file_sg_idx));
break;
}
}
file_sg_idx = 0;
}
}
void MainWindow::newSectionGroupDirSequence_treeWidget(SectionGroup* sectionGroup, SectionGroup* newSectionGroup, QTreeWidgetItem* sectionGroupItem)
{
/* This is a Recursive Function */
int sg_idx = 0;
for(sg_idx = 0; sectionGroup->sectionGroupArray.size(); sg_idx++)
{
if(newSectionGroup->parentDir == sectionGroup->sectionGroupArray.at(sg_idx)->location)
{
sectionGroup->sectionGroupArray.append(newSectionGroup);
break;
} else {
newSectionGroupDirSequence_treeWidget(sectionGroup, newSectionGroup, sectionGroupItem);
}
}
}
void MainWindow::updateNotebookDirSequence_treeWidget(SectionGroup* sectionGroup, QTreeWidgetItem* sectionChildItem)
{
/* This is a Recursive Function */
int idx = 0; // File Index (including Directory)
int dir_idx = 0; // Directory Index
for(idx = 0; idx < sectionGroup->files.size(); idx++)
{
QFileInfo fileInfo(sectionGroup->files.at(idx));
if(fileInfo.fileName() != "." && fileInfo.fileName() != ".." && !fileInfo.fileName().endsWith(".sectgr") && !fileInfo.fileName().endsWith("~"))
{
if(fileInfo.isFile() == true)
{
// Section
sectionChildItem->addChild(notebookList.createSectionIcon(fileInfo));
} else {
// Section Group
QTreeWidgetItem* subSectionGroupNameItem = notebookList.createSectionGroupIcon(sectionGroup->sectionGroupArray.at(dir_idx));
sectionChildItem->addChild(subSectionGroupNameItem);
updateNotebookDirSequence_treeWidget(sectionGroup->sectionGroupArray.at(dir_idx), subSectionGroupNameItem);
dir_idx++;
}
}
}
idx = 0;
dir_idx = 0;
}
void MainWindow::updateNotebookDirSequence_fileToSecGr(SectionGroup* sectionGroup)
{
/* This is a Recursive Function */
int sg_idx = 0;
for(sg_idx = 0; sg_idx < sectionGroup->sectionGroupArray.size(); sg_idx++)
{
QFileInfo nbFileInfo(sectionGroup->sectionGroupArray.at(sg_idx)->location);
QDir directory(sectionGroup->sectionGroupArray.at(sg_idx)->location);
directory.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
foreach(QFileInfo fileInfo, directory.entryInfoList())
{
if(!sectionGroup->sectionGroupArray.at(sg_idx)->files.contains(fileInfo.absoluteFilePath()) && !fileInfo.fileName().endsWith(".sectgr")
&& fileInfo.fileName() != "." && fileInfo.fileName() != ".." && fileInfo.fileName().endsWith("~"))
{
sectionGroup->sectionGroupArray.at(sg_idx)->files.append(fileInfo.absoluteFilePath());
}
}
updateNotebookDirSequence_fileToSecGr(sectionGroup->sectionGroupArray.at(sg_idx));
}
}
void MainWindow::deleteNotebookDirSequence_findFile(SectionGroup* sectionGroup, QString selectedItem)
{
int file_idx = 0;
for(file_idx = 0; file_idx < sectionGroup->files.size(); file_idx++)
{
if(sectionGroup->files.at(file_idx) == selectedItem)
{
if(QFileInfo(sectionGroup->files.at(file_idx)).isDir())
{
int sg2_idx = 0;
for(sg2_idx = 0; sg2_idx < sectionGroup->sectionGroupArray.size(); sg2_idx++)
{
if(sectionGroup->sectionGroupArray.at(sg2_idx)->location == selectedItem)
{
sectionGroup->sectionGroupArray.removeAt(sg2_idx);
}
}
}
sectionGroup->files.removeAt(file_idx);
} else {
QFileInfo fileInfo(sectionGroup->files.at(file_idx));
if(fileInfo.isDir())
{
int sg_idx = 0;
for(sg_idx = 0; sg_idx < sectionGroup->sectionGroupArray.size(); sg_idx++)
{
// Section Group
deleteNotebookDirSequence_findFile(sectionGroup->sectionGroupArray.at(sg_idx), selectedItem);
}
}
}
}
}
/* Menu Items */
void MainWindow::on_actionNew_Section_triggered()
{
on_newSection_Button_clicked();
}
void MainWindow::on_actionNew_Section_Group_triggered()
{
on_newSectionGroup_Button_clicked();
}
void MainWindow::on_actionNew_Notebook_triggered()
{
on_newNotebook_Button_clicked();
}
void MainWindow::on_actionOpen_Notebook_triggered()
{
on_openNotebook_Button_clicked();
}
void MainWindow::on_actionOpen_Section_triggered()
{
on_openSection_Button_clicked();
}
void MainWindow::on_actionUnfiled_Notes_triggered()
{
on_unfiledNotes_Button_clicked();
}
void MainWindow::on_actionClose_Notebook_triggered()
{
on_closeNotebook_Button_clicked();
}
void MainWindow::on_actionClose_All_Notebooks_triggered()
{
on_closeAllNotebooksButton_clicked();
}
void MainWindow::on_actionExit_triggered()
{
ExitProgram();
QApplication::quit();
}
void MainWindow::on_actionDeleteItem_triggered()
{
on_deleteSelectedItem_Button_clicked();
}
void MainWindow::on_actionImport_Section_triggered()
{
on_importSection_Button_clicked();
}
void MainWindow::on_actionExport_Section_triggered()
{
on_exportSection_Button_clicked();
}
void MainWindow::on_actionSettings_triggered()
{
on_generalSettings_Button_clicked();
}
void MainWindow::on_actionApplication_Launchers_triggered()
{
uiSettings->setSettingsTabPage(1);
if(!uiSettings->exec()) return;
}
void MainWindow::on_actionHelp_triggered()
{
uiSettings->setSettingsTabPage(2);
if(!uiSettings->exec()) return;
}
void MainWindow::on_actionAbout_triggered()
{
uiSettings->setSettingsTabPage(3);
if(!uiSettings->exec()) return;
}
void MainWindow::on_actionItem_Properties_triggered()
{
on_itemPropertiesButton_clicked();
}
void MainWindow::on_actionRefresh_Notebook_List_triggered()
{
on_refreshNotebookListButton_clicked();
}
void MainWindow::on_actionExpand_All_Notebooks_triggered()
{
ui->notebookList->expandToDepth(0);
}
void MainWindow::on_actionExpand_All_Items_triggered()
{
ui->notebookList->expandAll();
}
void MainWindow::on_actionCollapse_All_Notebooks_triggered()
{
ui->notebookList->collapseAll();
}