diff --git a/copyItemDialog.cpp b/copyItemDialog.cpp new file mode 100644 index 0000000..23f167c --- /dev/null +++ b/copyItemDialog.cpp @@ -0,0 +1,323 @@ +#include "copyItemDialog.h" +#include "ui_copyItemDialog.h" + +CopyItemDialog::CopyItemDialog(bool moveItem, QStringList notebookColorList, QStringList notebookDirList, QStringList list, QString itemName, QString itemLocation, QWidget *parent) : + QDialog(parent), + ui(new Ui::CopyItemDialog) +{ + setMoveItemState(moveItem); + setNotebookColorList(notebookColorList); + setNotebookDirList(notebookDirList); + setDirectories(list); + setFileName(itemName); + setFileLocation(itemLocation); + ui->setupUi(this); + init(); +} + +CopyItemDialog::~CopyItemDialog() +{ + delete ui; +} + +void CopyItemDialog::init() +{ + ui->fileNameBox->setText(getFileName()); + if(moveItemState == false) + { + // Copying Item: + ui->moveItemState_Label->setText("Copy Item:"); + } else { + // Moving Item: + ui->moveItemState_Label->setText("Move Item:"); + } + addItemsToDirectory(); +} +void CopyItemDialog::addItemsToDirectory() +{ + int idx = 0; + for(idx = 0; idx < getDirectories().size(); idx++) + { + if(!getDirectories().at(idx).startsWith(" ")) + { + ui->directorySelection->addItem(SetNotebookIcon(notebookcolorlist.at(idx)), getDirectories().at(idx)); + } else { + ui->directorySelection->addItem(SetSectionGroupIcon(notebookcolorlist.at(idx)), getDirectories().at(idx)); + } + } +} + + +QIcon CopyItemDialog::SetNotebookIcon(QString notebookColor) +{ + QIcon icon; + QString iconPath = "../NoteBinder/Icons"; + if(!QDir(iconPath).exists()) + { + return icon; + } + if(notebookColor == "Red") { + icon = QIcon(iconPath + "/NotebookIcon_Red.png"); + } else if(notebookColor == "Blue") { + icon = QIcon(iconPath + "/NotebookIcon_Blue.png"); + } else if(notebookColor == "Purple") { + icon = QIcon(iconPath + "/NotebookIcon_Purple.png"); + } else if(notebookColor == "Orange") { + icon = QIcon(iconPath + "/NotebookIcon_Orange.png"); + } else if(notebookColor == "Yellow") { + icon = QIcon(iconPath + "/NotebookIcon_Yellow.png"); + } else if(notebookColor == "Green") { + icon = QIcon(iconPath + "/NotebookIcon_Green.png"); + } else if(notebookColor == "Cyan") { + icon = QIcon(iconPath + "/NotebookIcon_Cyan.png"); + } else if(notebookColor == "Tan") { + icon = QIcon(iconPath + "/NotebookIcon_Tan.png"); + } else if(notebookColor == "Teal") { + icon = QIcon(iconPath + "/NotebookIcon_Teal.png"); + } else if(notebookColor == "Red Chalk") { + icon = QIcon(iconPath + "/NotebookIcon_RedChalk.png"); + } else if(notebookColor == "Blue Mist") { + icon = QIcon(iconPath + "/NotebookIcon_BlueMist.png"); + } else if(notebookColor == "Purple Mist") { + icon = QIcon(iconPath + "/NotebookIcon_PurpleMist.png"); + } else if(notebookColor == "Magenta") { + icon = QIcon(iconPath + "/NotebookIcon_Magenta.png"); + } else if(notebookColor == "Lemon Lime") { + icon = QIcon(iconPath + "/NotebookIcon_LemonLime.png"); + } else if(notebookColor == "Apple") { + icon = QIcon(iconPath + "/NotebookIcon_Apple.png"); + } else if(notebookColor == "Silver") { + icon = QIcon(iconPath + "/NotebookIcon_Silver.png"); + } else if(notebookColor == "Black") { + icon = QIcon(iconPath + "/NotebookIcon_Black.png"); + } else { + // If it's either White/None or an invalid value, set to the white icon + icon = QIcon(iconPath + "/NotebookIcon_White.png"); + } + return icon; +} +QIcon CopyItemDialog::SetSectionGroupIcon(QString sectionGroupColor) +{ + QIcon icon; + QString iconPath = "../NoteBinder/Icons"; + if(!QDir(iconPath).exists()) + { + return icon; + } + if(sectionGroupColor == "Red") { + icon = QIcon(iconPath + "/SectionGroupIcon_Red.png"); + } else if(sectionGroupColor == "Blue") { + icon = QIcon(iconPath + "/SectionGroupIcon_Blue.png"); + } else if(sectionGroupColor == "Purple") { + icon = QIcon(iconPath + "/SectionGroupIcon_Purple.png"); + } else if(sectionGroupColor == "Orange") { + icon = QIcon(iconPath + "/SectionGroupIcon_Orange.png"); + } else if(sectionGroupColor == "Yellow") { + icon = QIcon(iconPath + "/SectionGroupIcon_Yellow.png"); + } else if(sectionGroupColor == "Green") { + icon = QIcon(iconPath + "/SectionGroupIcon_Green.png"); + } else if(sectionGroupColor == "Cyan") { + icon = QIcon(iconPath + "/SectionGroupIcon_Cyan.png"); + } else if(sectionGroupColor == "Tan") { + icon = QIcon(iconPath + "/SectionGroupIcon_Tan.png"); + } else if(sectionGroupColor == "Teal") { + icon = QIcon(iconPath + "/SectionGroupIcon_Teal.png"); + } else if(sectionGroupColor == "Red Chalk") { + icon = QIcon(iconPath + "/SectionGroupIcon_RedChalk.png"); + } else if(sectionGroupColor == "Blue Mist") { + icon = QIcon(iconPath + "/SectionGroupIcon_BlueMist.png"); + } else if(sectionGroupColor == "Purple Mist") { + icon = QIcon(iconPath + "/SectionGroupIcon_PurpleMist.png"); + } else if(sectionGroupColor == "Magenta") { + icon = QIcon(iconPath + "/SectionGroupIcon_Magenta.png"); + } else if(sectionGroupColor == "Lemon Lime") { + icon = QIcon(iconPath + "/SectionGroupIcon_LemonLime.png"); + } else if(sectionGroupColor == "Apple") { + icon = QIcon(iconPath + "/SectionGroupIcon_Apple.png"); + } else if(sectionGroupColor == "Silver") { + icon = QIcon(iconPath + "/SectionGroupIcon_Silver.png"); + } else if(sectionGroupColor == "Black") { + icon = QIcon(iconPath + "/SectionGroupIcon_Black.png"); + } else { + // If it's either White/None or an invalid value, set to the white icon + icon = QIcon(iconPath + "/SectionGroupIcon_White.png"); + } + return icon; +} + +/* Getters */ +bool CopyItemDialog::getMoveItemState() const +{ + return moveItemState; +} +QStringList CopyItemDialog::getDirectories() const +{ + return var_directoryList; +} +QStringList CopyItemDialog::getNotebookDirList() const +{ + return notebookdirList; +} +QStringList CopyItemDialog::getNotebookColorList() const +{ + return notebookcolorlist; +} +QString CopyItemDialog::getFileName() const +{ + return var_itemName; +} +QString CopyItemDialog::getFileLocation() const +{ + return var_itemLocation; +} + + +/* Setters */ +void CopyItemDialog::setMoveItemState(bool updateMoveState) +{ + moveItemState = updateMoveState; +} +void CopyItemDialog::setDirectories(QStringList dirList) +{ + var_directoryList = dirList; +} +void CopyItemDialog::setNotebookDirList(QStringList nbDirList) +{ + notebookdirList = nbDirList; +} +void CopyItemDialog::setNotebookColorList(QStringList nbColorList) +{ + notebookcolorlist = nbColorList; +} +void CopyItemDialog::setFileName(QString newItemName) +{ + var_itemName = newItemName; +} +void CopyItemDialog::setFileLocation(QString newItemLocation) +{ + var_itemLocation = newItemLocation; +} + +void CopyItemDialog::on_buttonBox_accepted() +{ + if(ui->fileNameBox->text() != "") + { + QString fullFileName = getFileLocation(); + setFileName(ui->fileNameBox->text()); + QString newFullFileName = getNotebookDirList().at(ui->directorySelection->currentIndex()) + QDir::separator() + getFileName(); + QFile file(newFullFileName); + QDir dir(fullFileName); + QFileInfo fileInfo(newFullFileName); + if(fileInfo.absoluteFilePath() == fullFileName) + { + reject(); // Cannot write onto itself. + } else { + if(!file.exists()) + { + if(fileInfo.isFile()) + { + // File + file.copy(fullFileName, newFullFileName); + } else { + copyRecursively(fullFileName, newFullFileName); + QFile fileSectGr(newFullFileName + QDir::separator() + "sectiongroup.sectgr"); + QStringList fileItems; + // Read This file + if(fileSectGr.exists()) + { + if(fileSectGr.open(QIODevice::ReadOnly)) + { + QTextStream in(&fileSectGr); + while(!in.atEnd()) + { + fileItems += in.readLine(); + } + } + fileSectGr.remove(); + if (fileSectGr.open(QIODevice::ReadWrite)) { + QTextStream in(&fileSectGr); + in << fileInfo.fileName() << "\n" << fileItems.at(1) << "\n"; + } + fileSectGr.close(); + } + } + setFileLocation(newFullFileName); + accept(); + } else { + QMessageBox messageBox; + QFont fontSize; + fontSize.setPointSize(12); + messageBox.setWindowTitle("Replace Existing Item?"); + messageBox.setFont(fontSize); + messageBox.setText("Item already exists! Do you want to overwrite it?"); + messageBox.setStandardButtons(QMessageBox::Yes); + messageBox.addButton(QMessageBox::No); + messageBox.setDefaultButton(QMessageBox::No); + if(messageBox.exec() == QMessageBox::Yes) + { + if(fileInfo.isFile()) + { + // File + file.copy(fullFileName, newFullFileName); + } else { + copyRecursively(fullFileName, newFullFileName); + QFile fileSectGr(newFullFileName + QDir::separator() + "sectiongroup.sectgr"); + QStringList fileItems; + // Read This file + if(fileSectGr.exists()) + { + if(fileSectGr.open(QIODevice::ReadOnly)) + { + QTextStream in(&fileSectGr); + while(!in.atEnd()) + { + fileItems += in.readLine(); + } + } + fileSectGr.remove(); + if (fileSectGr.open(QIODevice::ReadWrite)) { + QTextStream in(&fileSectGr); + in << fileInfo.fileName() << "\n" << fileItems.at(1) << "\n"; + } + fileSectGr.close(); + } + } + setFileLocation(newFullFileName); + accept(); + } else { + reject(); + } + } + } + } +} +void CopyItemDialog::on_buttonBox_rejected() +{ + reject(); +} + +bool CopyItemDialog::copyRecursively(const QString &srcFilePath, const QString &tgtFilePath) +{ + /* Function written by ssendeavour: https://gist.github.com/ssendeavour/7324701#file-copy-recursively-cpp */ + QFileInfo srcFileInfo(srcFilePath); + if (srcFileInfo.isDir()) + { + QDir targetDir(tgtFilePath); + targetDir.cdUp(); + if (!targetDir.mkdir(QFileInfo(tgtFilePath).fileName())) + return false; + QDir sourceDir(srcFilePath); + QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); + foreach (const QString &fileName, fileNames) + { + const QString newSrcFilePath = srcFilePath + QDir::separator() + fileName; + const QString newTgtFilePath = tgtFilePath + QDir::separator() + fileName; + if (!copyRecursively(newSrcFilePath, newTgtFilePath)) + return false; + } + } else { + if (!QFile::copy(srcFilePath, tgtFilePath)) + return false; + } + return true; +} diff --git a/copyItemDialog.h b/copyItemDialog.h new file mode 100644 index 0000000..e8c9541 --- /dev/null +++ b/copyItemDialog.h @@ -0,0 +1,62 @@ +#ifndef COPYITEMDIALOG_H +#define COPYITEMDIALOG_H + +#include +#include +#include +#include "notebook.h" +#include "sectiongroup.h" +#include "notebooklist.h" +#include "notebookmanager.h" + +namespace Ui { +class CopyItemDialog; +} + +class CopyItemDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CopyItemDialog(bool moveItem, QStringList notebookColorList, QStringList notebookDirList, QStringList list, QString itemName, QString itemLocation, QWidget *parent = nullptr); + ~CopyItemDialog(); + + void init(); + void addItemsToDirectory(); + /* Function written by ssendeavour: https://gist.github.com/ssendeavour/7324701#file-copy-recursively-cpp */ + static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath); + + QIcon SetNotebookIcon(QString notebookColor); + QIcon SetSectionGroupIcon(QString sectionGroupColor); + + /* Getters */ + bool getMoveItemState() const; + QStringList getDirectories() const; + QStringList getNotebookDirList() const; + QStringList getNotebookColorList() const; + QString getFileName() const; + QString getFileLocation() const; + + /* Setters */ + void setMoveItemState(bool updateMoveState); + void setDirectories(QStringList dirList); + void setNotebookDirList(QStringList nbDirList); + void setNotebookColorList(QStringList nbColorList); + void setFileName(QString newItemName); + void setFileLocation(QString newItemLocation); + +private slots: + void on_buttonBox_accepted(); + void on_buttonBox_rejected(); + +private: + Ui::CopyItemDialog *ui; + bool moveItemState; + QString var_itemName; + QString var_itemLocation; + QStringList notebookdirList; // Actual Filepaths of each Notebook or Section Group. + QStringList var_directoryList; // Directories displayed on the ComboBox of Directory List + QStringList notebookcolorlist; // Icon Colors of Notebook or Section Group +}; + +#endif // COPYITEMDIALOG_H diff --git a/copyItemDialog.ui b/copyItemDialog.ui new file mode 100644 index 0000000..38d60b5 --- /dev/null +++ b/copyItemDialog.ui @@ -0,0 +1,123 @@ + + + CopyItemDialog + + + + 0 + 0 + 535 + 221 + + + + Copy/Move Item + + + + + + + + + 12 + + + + Copy/Move Item: + + + + + + + + 12 + + + + + + + + + + + + + + + + 12 + + + + Select Notebook or Section Group: + + + + + + + + 12 + + + + + 24 + 24 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + CopyItemDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + CopyItemDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..17a180b --- /dev/null +++ b/main.cpp @@ -0,0 +1,16 @@ +/* DrewTechs + * Note Binder + * @Version 1.0 + */ + +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..78e86ba --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,1572 @@ + /* 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; + + 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 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 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 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(¬ebookList, 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 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(); +} +