#include "settings.h" #include "ui_settings.h" Settings::Settings(QString newDefaultNotebookPath, QString newOpenedNotebookList, QString newGeneralSettingsConfigFile, QString newApplicationLauncherConfigFile, QList newApplicationLaunchers, int tabPage, QWidget *parent) : QDialog(parent), ui(new Ui::Settings) { setDefaultNotebookPath(newDefaultNotebookPath); setOpenNotebookList(newOpenedNotebookList); setGeneralSettingsConfigFile(newGeneralSettingsConfigFile); setApplicationLauncherConfigFile(newApplicationLauncherConfigFile); int launcher_idx = 0; for(launcher_idx = 0; launcher_idx < newApplicationLaunchers.size(); launcher_idx++) { appendApplicationLauncher(newApplicationLaunchers.at(launcher_idx)); } ui->setupUi(this); init(); } Settings::~Settings() { delete ui; } void Settings::init() { // About Page ui->versionLabel->setText("Version: " + getProgramVersion()); ui->authorLabel->setText("Author: " +getProgramAuthor()); QPixmap pixmap("../NoteBinder/NoteBinderLogo.png"); pixmap.scaled(300,225,Qt::KeepAspectRatio,Qt::FastTransformation); ui->ApplicationLogoLabel->setPixmap(pixmap); ui->ApplicationLogoLabel->adjustSize(); // General Settings ui->settingsTabs->setCurrentIndex(settingsTabPage); ui->defaultNotebookPath_Field->setText(defaultNotebookPath); ui->generalSettingsConfig_Field->setText(generalSettingsConfigFile); ui->applicationLauncherConfig_Field->setText(applicationLauncherConfigFile); ui->notebookListConfig_Field->setText(openedNotebookList); helpList_DisplayItem(1); // Display First Page by default. int launcher_idx = 0; for(launcher_idx = 0; launcher_idx < applicationLaunchers.size(); launcher_idx++) { QTreeWidgetItem* launcherItem = new QTreeWidgetItem; launcherItem->setText(0, applicationLaunchers.at(launcher_idx)->getApplicationName()); int str_idx = 0; QString Extensions; QStringList ExtensionList = applicationLaunchers.at(launcher_idx)->getApplicationExtensions(); for(str_idx = 0; str_idx < ExtensionList.size(); str_idx++) { if(str_idx == ExtensionList.size() - 1) { Extensions += ExtensionList.at(str_idx); } else { Extensions += ExtensionList.at(str_idx) + ","; } } launcherItem->setText(1, Extensions); launcherItem->setText(2, applicationLaunchers.at(launcher_idx)->getApplicationLocation()); ui->applicationLauncherList->addTopLevelItem(launcherItem); } ui->helpItems->expandAll(); } void Settings::on_addApplication_Button_clicked() { // Create New Application Launcher AddApplicationLauncher* addAppLauncher = new AddApplicationLauncher(); if(!addAppLauncher->exec()) return; ApplicationLaunchers* newAppLauncher = addAppLauncher->getApplicationLauncher(); applicationLaunchers.append(newAppLauncher); QTreeWidgetItem* item = new QTreeWidgetItem(); item->setText(0, newAppLauncher->getApplicationName()); int str_idx = 0; QString Extensions = ""; QStringList ExtensionList = newAppLauncher->getApplicationExtensions(); for(str_idx = 0; str_idx < ExtensionList.size(); str_idx++) { if(str_idx == ExtensionList.size() - 1) { Extensions += ExtensionList.at(str_idx); } else { Extensions += ExtensionList.at(str_idx) + ","; } } item->setText(1, Extensions); item->setText(2, newAppLauncher->getApplicationLocation()); ui->applicationLauncherList->insertTopLevelItem(ui->applicationLauncherList->topLevelItemCount(), item); } void Settings::on_editApplication_Button_clicked() { // Edit Application Launcher on the List QModelIndex index = ui->applicationLauncherList->currentIndex(); int idx = index.row(); if(idx >= 0) { AddApplicationLauncher* addAppLauncher = new AddApplicationLauncher(applicationLaunchers.at(idx)); if(!addAppLauncher->exec()) return; applicationLaunchers.removeAt(idx); ApplicationLaunchers* newAppLauncher = addAppLauncher->getApplicationLauncher(); applicationLaunchers.insert(idx, newAppLauncher); QTreeWidgetItem* item = ui->applicationLauncherList->currentItem(); item->setText(0, newAppLauncher->getApplicationName()); int str_idx = 0; QString Extensions = ""; QStringList ExtensionList = newAppLauncher->getApplicationExtensions(); for(str_idx = 0; str_idx < ExtensionList.size(); str_idx++) { if(str_idx == ExtensionList.size() - 1) { Extensions += ExtensionList.at(str_idx); } else { Extensions += ExtensionList.at(str_idx) + ","; } } item->setText(1, Extensions); item->setText(2, newAppLauncher->getApplicationLocation()); } // idx will be at -1 if nothing is selected indicating out of bounds, to solve that the item has to be selected to open the launcher. } void Settings::on_removeApplication_Button_clicked() { // Remove Application Launcher from the List. QModelIndex index = ui->applicationLauncherList->currentIndex(); int idx = index.row(); if(idx >= 0) { QMessageBox messageBox; QFont fontSize; fontSize.setPointSize(12); QString s_txt = ui->applicationLauncherList->currentItem()->text(0); messageBox.setWindowTitle("Delete Application Launcher"); messageBox.setFont(fontSize); messageBox.setText("Are you sure you want to remove " + s_txt + " from the list?"); messageBox.setStandardButtons(QMessageBox::Yes); messageBox.addButton(QMessageBox::No); messageBox.setDefaultButton(QMessageBox::No); if(messageBox.exec() == QMessageBox::Yes) { delete ui->applicationLauncherList->currentItem(); applicationLaunchers.removeAt(idx); } } } void Settings::on_selectDir_defaultNbPath_Button_clicked() { QFileDialog dialog(this); dialog.setFileMode(QFileDialog::DirectoryOnly); dialog.setNameFilter(tr("Directory")); QString fileName = dialog.getExistingDirectory(this, tr("Open File"), QDir().homePath() + "/Documents", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); // Open Dialog if(fileName != "") { ui->defaultNotebookPath_Field->setText(fileName); setDefaultNotebookPath(fileName); } } void Settings::on_selectDir_generalSettingConf_Button_clicked() { QFileDialog dialog(this); dialog.setFileMode(QFileDialog::AnyFile); dialog.setNameFilter(tr("Config File")); QString fileName = dialog.getSaveFileName(this, tr("Save File"), QDir().homePath() + "/.config/notebinder/", tr("Config File (*.conf)")); // Open Dialog if(fileName != "") { ui->generalSettingsConfig_Field->setText(fileName); setGeneralSettingsConfigFile(fileName); } } void Settings::on_selectDir_appLauncher_Button_clicked() { QFileDialog dialog(this); dialog.setFileMode(QFileDialog::AnyFile); dialog.setNameFilter(tr("Config File")); QString fileName = dialog.getSaveFileName(this, tr("Save File"), QDir().homePath() + "/.config/notebinder/", tr("Config File (*.conf)")); // Open Dialog if(fileName != "") { ui->applicationLauncherConfig_Field->setText(fileName); setApplicationLauncherConfigFile(fileName); } } void Settings::on_selectDir_nbListConfig_Button_clicked() { QFileDialog dialog(this); dialog.setFileMode(QFileDialog::AnyFile); dialog.setNameFilter(tr("Config File")); QString fileName = dialog.getSaveFileName(this, tr("Save File"), QDir().homePath() + "/.config/notebinder/", tr("Config File (*.conf)")); // Open Dialog if(fileName != "") { ui->notebookListConfig_Field->setText(fileName); setOpenNotebookList(fileName); } } void Settings::on_helpItems_itemSelectionChanged() { QString itemSelected = ui->helpItems->currentItem()->text(0); ui->helpInformation->clear(); if(itemSelected == "1) Introduction") helpList_DisplayItem(1); else if(itemSelected == "1.1) What does Note Binder Application Do?") helpList_DisplayItem(2); else if(itemSelected == "1.2) Why use this Application?") helpList_DisplayItem(3); else if(itemSelected == "2) Notebook Management") helpList_DisplayItem(4); else if(itemSelected == "2.1) Notebook") helpList_DisplayItem(5); else if(itemSelected == "2.1.1) Create/Open Notebook") helpList_DisplayItem(6); else if(itemSelected == "2.1.2) Close/Remove Notebook") helpList_DisplayItem(7); else if(itemSelected == "2.2) Section") helpList_DisplayItem(8); else if(itemSelected == "2.2.1) Create/Open Sections") helpList_DisplayItem(9); else if(itemSelected == "2.2.2) Importing a Section to Notebook") helpList_DisplayItem(10); else if(itemSelected == "2.2.3) Export Section") helpList_DisplayItem(11); else if(itemSelected == "2.3) Section Group") helpList_DisplayItem(12); else if(itemSelected == "2.4) Unfiled Notes") helpList_DisplayItem(13); else if(itemSelected == "3) Application Settings") helpList_DisplayItem(14); else if(itemSelected == "3.1) Configuration Files") helpList_DisplayItem(15); else if(itemSelected == "3.2) Application Launchers") helpList_DisplayItem(16); else helpList_DisplayItem(1); } void Settings::helpList_DisplayItem(int pageSelected) { QString helpPagesDir = "../NoteBinder/HelpText"; QString helpPageFile; switch(pageSelected) { case 1: helpPageFile = helpPagesDir + QDir::separator() + "Page01"; break; case 2: helpPageFile = helpPagesDir + QDir::separator() + "Page02"; break; case 3: helpPageFile = helpPagesDir + QDir::separator() + "Page03"; break; case 4: helpPageFile = helpPagesDir + QDir::separator() + "Page04"; break; case 5: helpPageFile = helpPagesDir + QDir::separator() + "Page05"; break; case 6: helpPageFile = helpPagesDir + QDir::separator() + "Page06"; break; case 7: helpPageFile = helpPagesDir + QDir::separator() + "Page07"; break; case 8: helpPageFile = helpPagesDir + QDir::separator() + "Page08"; break; case 9: helpPageFile = helpPagesDir + QDir::separator() + "Page09"; break; case 10: helpPageFile = helpPagesDir + QDir::separator() + "Page10"; break; case 11: helpPageFile = helpPagesDir + QDir::separator() + "Page11"; break; case 12: helpPageFile = helpPagesDir + QDir::separator() + "Page12"; break; case 13: helpPageFile = helpPagesDir + QDir::separator() + "Page13"; break; case 14: helpPageFile = helpPagesDir + QDir::separator() + "Page14"; break; case 15: helpPageFile = helpPagesDir + QDir::separator() + "Page15"; break; case 16: helpPageFile = helpPagesDir + QDir::separator() + "Page16"; break; default: helpPageFile = helpPagesDir + QDir::separator() + "Page01"; break; } QFile file(helpPageFile); if(file.exists()) { QString readData; if(file.open(QIODevice::ReadOnly)|QIODevice::Text) { QTextStream in(&file); while(!in.atEnd()) { readData = in.readAll(); } } ui->helpInformation->setPlainText(readData); } else { ui->helpInformation->setPlainText("Error: Help Page Information not available!"); } } void Settings::appendApplicationLauncher(ApplicationLaunchers* launcher) { applicationLaunchers.append(launcher); } void Settings::removeApplicationLauncherAt(int idx) { applicationLaunchers.removeAt(idx); } /* Setter Functions */ void Settings::setDefaultNotebookPath(QString newDefaultNotebookPath) { defaultNotebookPath = newDefaultNotebookPath; } void Settings::setOpenNotebookList(QString newOpenedNotebookList) { openedNotebookList = newOpenedNotebookList; } void Settings::setGeneralSettingsConfigFile(QString newGeneralSettingsConfigFile) { generalSettingsConfigFile = newGeneralSettingsConfigFile; } void Settings::setApplicationLauncherConfigFile(QString newApplicationLauncherConfigFile) { applicationLauncherConfigFile = newApplicationLauncherConfigFile; } void Settings::setSettingsTabPage(int newSettingsTab) { settingsTabPage = newSettingsTab; ui->settingsTabs->setCurrentIndex(settingsTabPage); } void Settings::setProgramVersion(QString progVersion) { programAuthor = progVersion; } void Settings::setProgramAuthor(QString progAuthor) { programAuthor = progAuthor; } /* Getter Functions */ QString Settings::getDefaultNotebookPath() { return defaultNotebookPath; } QString Settings::getOpenedNotebookList() { return openedNotebookList; } QString Settings::getGeneralSettingsConfigFile() { return generalSettingsConfigFile; } QString Settings::getApplicationLauncherConfigFile() { return applicationLauncherConfigFile; } ApplicationLaunchers* Settings::getApplicationLauncherAt(int idx) { return applicationLaunchers.at(idx); } int Settings::getSettingsTabPage() { return settingsTabPage; } QString Settings::getProgramVersion() { return programVersion; } QString Settings::getProgramAuthor() { return programAuthor; } void Settings::on_dialogButtonBox_accepted() { accept(); } void Settings::on_dialogButtonBox_rejected() { reject(); }