Example #1
0
void AppearancePreferences::saveValues() {
    int index = systemNotifier->currentIndex();
    QString sysnotifier = systemNotifier->itemData(index, Qt::UserRole).toString();

    global.setNewNoteFocusToTitle(newNoteFocusOnTitle->isChecked());
    global.setDeleteConfirmation(this->confirmDeletes->isChecked());
    global.settings->beginGroup("Appearance");
    global.settings->setValue("disableEditingOnStartup", disableEditingOnStartup->isChecked());
    global.settings->setValue("forceWebFonts", forceWebFonts->isChecked());
    global.settings->setValue("showTrayIcon", showTrayIcon->isChecked());
    global.settings->setValue("showPDFs", showPDFs->isChecked());
    global.autoHideEditorToolbar = this->autoHideEditorButtonbar->isChecked();
    global.settings->setValue("autoHideEditorToolbar", global.autoHideEditorToolbar);
    global.settings->setValue("mouseMiddleClickOpen", mouseMiddleClickAction->currentIndex());
    global.settings->setValue("traySingleClickAction", traySingleClickAction->currentIndex());
    global.settings->setValue("trayMiddleClickAction", trayMiddleClickAction->currentIndex());
    global.settings->setValue("systemNotifier", sysnotifier);
    global.settings->remove("trayDoubleClickAction");
    global.pdfPreview = showPDFs->isChecked();
    if (minimizeToTray!= NULL)
        global.settings->setValue("minimizeToTray", minimizeToTray->isChecked());
    else
        global.settings->remove("minimizeToTray");
    if (closeToTray != NULL)
        global.settings->setValue("closeToTray", closeToTray->isChecked());
    else
        global.settings->remove("closeToTray");
    global.settings->setValue("showSplashScreen", showSplashScreen->isChecked());
    global.settings->setValue("startMinimized", startMinimized->isChecked());
    global.settings->setValue("showMissedReminders", showMissedReminders->isChecked());
    if (dynamicTotals->isChecked()) {
        global.settings->setValue("countBehavior", 1);
        global.countBehavior = Global::CountAll;
    } else {
        global.settings->setValue("countBehavior", 2);
        global.countBehavior = Global::CountNone;
    }
    index = defaultNotebookOnStartup->currentIndex();
    int value = defaultNotebookOnStartup->itemData(index).toInt();
    global.settings->setValue("startupNotebook", value);

    //  Save default font & size
    if (webSettingsChanged) {
        int idx = defaultFontChooser->currentIndex();
        global.defaultFont = defaultFontChooser->itemData(idx, Qt::UserRole).toString();
        idx = defaultFontSizeChooser->currentIndex();
        global.defaultFontSize = defaultFontSizeChooser->itemData(idx, Qt::UserRole).toInt();
        idx = defaultGuiFontSizeChooser->currentIndex();
        global.defaultGuiFontSize = defaultGuiFontSizeChooser->itemData(idx, Qt::UserRole).toInt();
        idx = defaultGuiFontChooser->currentIndex();
        global.defaultGuiFont = defaultGuiFontChooser->itemData(idx, Qt::UserRole).toString();
        if (global.defaultGuiFont == "System Default")
            global.defaultGuiFont = "";
        if (global.defaultFont == "System Default")
            global.defaultFont = "";
        global.settings->setValue("defaultFont", global.defaultFont);
        global.settings->setValue("defaultFontSize", global.defaultFontSize);
        global.settings->setValue("defaultGuiFont", global.defaultGuiFont);
        global.settings->setValue("defaultGuiFontSize", global.defaultGuiFontSize);

        QWebSettings *settings = QWebSettings::globalSettings();
        settings->setFontFamily(QWebSettings::StandardFont, global.defaultFont);
        // QWebkit DPI is hard coded to 96. Hence, we calculate the correct
        // font size based on desktop logical DPI.
        if (global.defaultFontSize > 0) {
            settings->setFontSize(QWebSettings::DefaultFontSize, global.defaultFontSize * (QApplication::desktop()->logicalDpiX() / 96.0));
        }
    }


    // See if the user has overridden the window icon
//    index = windowThemeChooser->currentIndex();
//    QString userIcon = windowThemeChooser->itemData(index).toString();
//    if (userIcon != global.getResourceFileName(userIcon)) {
    //global.settings->setValue("windowIcon", userIcon);

    //Copy the nixnote2.desktop so we can override the app icon
    // Ideally, we could use QSettings since it is ini format, but
    // it puts [Desktop Entry] as [Desktop%20Enry], which screws
    // things up.
    QString systemFile = "/usr/share/applications/nixnote2.desktop";
    QFile systemIni(systemFile);
    QStringList desktopData;

    if (systemIni.open(QIODevice::ReadOnly)) {
        QTextStream data(&systemIni);
        QString line = data.readLine();
        while (!line.isNull()) {
            if (line.startsWith("Icon=")) {
                line = "Icon=" +global.getResourceFileName(global.resourceList,":windowIcon.png");
            }
            desktopData.append(line);
            line = data.readLine();
        }
    }
    systemIni.close();

    // Now, write it back out
    QString userFile =  QDir::homePath()+"/.local/share/applications/nixnote2.desktop";
    QFile userIni(userFile);
    if (userIni.open(QIODevice::WriteOnly)) {
        QTextStream data(&userIni);
        for (int i=0; i<desktopData.size(); i++) {
            data << desktopData[i] << "\n";
        }
    }
    userIni.close();

//    }

    // Setup if the user wants to start NixNote the next time they login.
    global.settings->setValue("autoStart", autoStart->isChecked());
    QString startFile =  QDir::homePath()+"/.config/autostart/nixnote2.desktop";
    QDir dir;
    dir.remove(startFile);
    if (autoStart->isChecked()) {
        //Copy the nixnote2.desktop to the ~/.config/autostart directory
        QString systemFile = "/usr/share/applications/nixnote2.desktop";
        QFile systemIni(systemFile);
        QStringList desktopData;

        if (systemIni.open(QIODevice::ReadOnly)) {
            QTextStream data(&systemIni);
            QString line = data.readLine();
            while (!line.isNull()) {
                if (line.startsWith("Icon=")) {
                    line = "Icon=" +global.getResourceFileName(global.resourceList,":windowIcon.png");
                }
                desktopData.append(line);
                line = data.readLine();
            }
        }
        systemIni.close();

        // Now, write it back out
        QString userFile =  QDir::homePath()+"/.config/autostart/nixnote2.desktop";
        QFile userIni(userFile);
        if (userIni.open(QIODevice::WriteOnly)) {
            QTextStream data(&userIni);
            for (int i=0; i<desktopData.size(); i++) {
                data << desktopData[i] << "\n";
            }
            data << "X-GNOME-Autostart-enabled=true";
        }
        userIni.close();
    }


    global.settings->endGroup();

}