AppearancePreferences::AppearancePreferences(QWidget *parent) :
    QWidget(parent)
{
    mainLayout = new QGridLayout();
    mainLayout->setAlignment(Qt::AlignTop);
    setLayout(mainLayout);
    int middleClickIndex = global.getMiddleClickAction();

    showTrayIcon = new QCheckBox(tr("Show tray icon"), this);
    showPDFs = new QCheckBox(tr("Display PDFs inline"), this);
    showSplashScreen = new QCheckBox(tr("Show splash screen on startup"), this);
    autoStart = new QCheckBox(tr("Start automatically at login"), this);
    showMissedReminders = new QCheckBox(tr("Show missed reminders on startup"), this);
    startMinimized = new QCheckBox(tr("Always Start minimized"), this);
    dynamicTotals = new QCheckBox(tr("Show notebook and tag totals"), this);
    autoHideEditorButtonbar = new QCheckBox(tr("Auto-Hide editor toolbar"), this);
    autoHideEditorButtonbar->setChecked(global.autoHideEditorToolbar);
    disableEditingOnStartup = new QCheckBox(tr("Disable note editing on statup"), this);

    traySingleClickAction = new QComboBox();
    traySingleClickAction->addItem(tr("Show/Hide NixNote"), 0);
    traySingleClickAction->addItem(tr("New Text Note"), 1);
    traySingleClickAction->addItem(tr("New Quick Note"), 2);
    traySingleClickAction->addItem(tr("Screen Capture"), 3);

    trayMiddleClickAction = new QComboBox();
    trayMiddleClickAction->addItem(tr("Show/Hide NixNote"), 0);
    trayMiddleClickAction->addItem(tr("New Text Note"), 1);
    trayMiddleClickAction->addItem(tr("New Quick Note"), 2);
    trayMiddleClickAction->addItem(tr("Screen Capture"), 3);

    mouseMiddleClickAction = new QComboBox();
    mouseMiddleClickAction->addItem(tr("Open New Tab"), MOUSE_MIDDLE_CLICK_NEW_TAB);
    mouseMiddleClickAction->addItem(tr("Open New Window"), MOUSE_MIDDLE_CLICK_NEW_WINDOW);
    mouseMiddleClickAction->setCurrentIndex(middleClickIndex);


    defaultGuiFontSizeChooser = new QComboBox();
    defaultFontChooser = new QComboBox();
    defaultFontSizeChooser = new QComboBox();
    connect(defaultFontChooser, SIGNAL(currentIndexChanged(QString)), this, SLOT(loadFontSizes(QString)));
    loadFontNames(defaultFontChooser, global.defaultFont);

    defaultGuiFontChooser = new QComboBox();
    connect(defaultGuiFontChooser, SIGNAL(currentIndexChanged(QString)), this, SLOT(loadGuiFontSizes(QString)));
    loadFontNames(defaultGuiFontChooser, global.defaultGuiFont);

    windowThemeChooser = new QComboBox();
    windowThemeChooser->addItem(tr("System Default"));
    windowThemeChooser->addItems(global.getThemeNames());


    defaultNotebookOnStartupLabel = new QLabel(tr("Startup Behavior"),this);
    defaultNotebookOnStartup = new QComboBox();
    defaultNotebookOnStartup->addItem(tr("Restore Selection Criteria"), UseLastViewedNotebook);
    defaultNotebookOnStartup->addItem(tr("Select Default Notebook"), UseDefaultNotebook);
    defaultNotebookOnStartup->addItem(tr("View All Notebooks"), UseAllNotebooks);

    int row=0;
    minimizeToTray = NULL;
    closeToTray = NULL;
    mainLayout->addWidget(showTrayIcon,row++,0);
    if (QSystemTrayIcon::isSystemTrayAvailable()) {
        minimizeToTray = new QCheckBox(tr("Minimize to tray"));
        closeToTray = new QCheckBox(tr("Close to tray"));
        mainLayout->addWidget(minimizeToTray, row++, 0);
        mainLayout->addWidget(closeToTray, row++, 0);
    }
    mainLayout->addWidget(showSplashScreen, row++,0);
    mainLayout->addWidget(autoHideEditorButtonbar, row++, 0);
    mainLayout->addWidget(showPDFs, row++,0);
    mainLayout->addWidget(showMissedReminders, row++, 0);
    mainLayout->addWidget(dynamicTotals, row++, 0);
    mainLayout->addWidget(startMinimized, row++, 0);
    mainLayout->addWidget(autoStart, row++, 0);
    mainLayout->addWidget(disableEditingOnStartup, row++, 0);
    mainLayout->addWidget(defaultNotebookOnStartupLabel,row,0);
    mainLayout->addWidget(defaultNotebookOnStartup, row++,1);

    mainLayout->addWidget(new QLabel(tr("Middle Click Open Behavior")), row,0);
    mainLayout->addWidget(mouseMiddleClickAction, row++, 1);

    mainLayout->addWidget(new QLabel(tr("Tray Icon Click Action")), row, 0);
    mainLayout->addWidget(traySingleClickAction, row++, 1);

    mainLayout->addWidget(new QLabel(tr("Tray Icon Middle Click Action")), row, 0);
    mainLayout->addWidget(trayMiddleClickAction, row++, 1);

    mainLayout->addWidget(new QLabel(tr("Default GUI Font*")), row, 0);
    mainLayout->addWidget(defaultGuiFontChooser, row++, 1);

    mainLayout->addWidget(new QLabel(tr("Default GUI Font Size*")), row, 0);
    mainLayout->addWidget(defaultGuiFontSizeChooser, row++, 1);

    mainLayout->addWidget(new QLabel(tr("Default Editor Font*")), row, 0);
    mainLayout->addWidget(defaultFontChooser, row++, 1);

    mainLayout->addWidget(new QLabel(tr("Default Editor Font Size*")), row, 0);
    mainLayout->addWidget(defaultFontSizeChooser, row++, 1);

    mainLayout->addWidget(new QLabel(""), row++, 0);
    mainLayout->addWidget(new QLabel(tr("* May require restart on some systems.")), row++, 0);

    global.settings->beginGroup("Appearance");

    disableEditingOnStartup->setChecked(global.settings->value("disableEditingOnStartup",false).toBool());
    int idx  = global.settings->value("traySingleClickAction", 0).toInt();
    idx = traySingleClickAction->findData(idx, Qt::UserRole);
    traySingleClickAction->setCurrentIndex(idx);
    idx  = global.settings->value("trayMiddleClickAction", 0).toInt();
    idx = traySingleClickAction->findData(idx, Qt::UserRole);
    trayMiddleClickAction->setCurrentIndex(idx);

    showTrayIcon->setChecked(global.settings->value("showTrayIcon", false).toBool());
    showPDFs->setChecked(global.settings->value("showPDFs", true).toBool());
    showSplashScreen->setChecked(global.settings->value("showSplashScreen", false).toBool());
    showMissedReminders->setChecked(global.settings->value("showMissedReminders", false).toBool());
    startMinimized->setChecked(global.settings->value("startMinimized", false).toBool());
    if (global.countBehavior == Global::CountAll)
        dynamicTotals->setChecked(true);
    else
        dynamicTotals->setChecked(false);
    autoStart->setChecked(global.settings->value("autoStart", false).toBool());
    int defaultNotebook = global.settings->value("startupNotebook", UseLastViewedNotebook).toInt();
    defaultNotebookOnStartup->setCurrentIndex(defaultNotebook);
    global.settings->endGroup();

    connect(showTrayIcon, SIGNAL(clicked(bool)), this, SLOT(showTrayIconChanged(bool)));

    if (minimizeToTray != NULL) {
        minimizeToTray->setChecked(global.minimizeToTray());
        if (!showTrayIcon->isChecked())
            minimizeToTray->setEnabled(false);
    }
    if (closeToTray != NULL) {
        closeToTray->setChecked(global.closeToTray());
        if (!showTrayIcon->isChecked())
            closeToTray->setEnabled(false);
    }

    this->setFont(global.getGuiFont(font()));
}
Example #2
0
//using namespace cv;
//*********************************************************************
//* Main entry point to the program.
//*********************************************************************
int main(int argc, char *argv[])
{
    signal(SIGSEGV, fault_handler);   // install our handler

    // Setup the QApplication so we can begin
    Application *a = new Application(argc, argv);
    global.application = a;

    // Setup the QLOG functions for debugging & messages
    QsLogging::Logger& logger = QsLogging::Logger::instance();
    logger.setLoggingLevel(QsLogging::TraceLevel);
//    const QString sLogPath(a->applicationDirPath());

    QsLogging::DestinationPtr debugDestination(
                QsLogging::DestinationFactory::MakeDebugOutputDestination() );
    logger.addDestination(debugDestination.get());

    // Begin setting up the environment
    StartupConfig startupConfig;
    global.argc = argc;
    global.argv = argv;

    startupConfig.accountId = -1;

    for (int i=1; i<=argc; i++) {
        QString parm(argv[i]);
        if (parm == "--help" || parm == "-?") {
            printf("\n\n");
            printf("NixNote command line options:\n");
            printf("  --help or -?                  Show this message\n");
            printf("  --accountId=<id>              Start with specified user account\n");
            printf("  --dontStartMinimized          Override option to start minimized\n");
            printf("  --disableEditing              Disable note editing\n");
            printf("  --enableIndexing              Enable background Indexing (can cause problems)\n");
            printf("  --openNote=<lid>              Open a specific note on startup\n");
            printf("  --forceSystemTrayAvailable    Force the program to accept that\n");
            printf("                                the desktop supports tray icons.\n");
            printf("  --startMinimized              Force a startup with NixNote minimized\n");
            printf("  --syncAndExit                 Synchronize and exit the program.\n");
            printf("\n\n");
            return 0;
        }
        if (parm.startsWith("--accountId=", Qt::CaseSensitive)) {
            parm = parm.mid(12);
            startupConfig.accountId = parm.toInt();
        }
        if (parm.startsWith("--openNote=", Qt::CaseSensitive)) {
            parm = parm.mid(11);
            startupConfig.startupNoteLid = parm.toInt();
        }
        if (parm == "--disableEditing") {
            startupConfig.disableEditing = true;
        }
        if (parm == "--dontStartMinimized") {
            startupConfig.forceNoStartMinimized = true;
        }
        if (parm == "--startMinimized") {
            startupConfig.forceStartMinimized = true;
        }
        if (parm == "--newNote") {
            startupConfig.startupNewNote = true;
        }
        if (parm == "--syncAndExit") {
            startupConfig.syncAndExit = true;
        }
        if (parm == "--enableIndexing") {
            startupConfig.enableIndexing = true;
        }
        if (parm == "--forceSystemTrayAvailable") {
            startupConfig.forceSystemTrayAvailable = true;
        }
    }

    startupConfig.programDirPath = global.getProgramDirPath() + QDir().separator();
    startupConfig.name = "NixNote";
    global.setup(startupConfig);

    QString logPath = global.fileManager.getLogsDirPath("")+"messages.log";
    QsLogging::DestinationPtr fileDestination(
                 QsLogging::DestinationFactory::MakeFileDestination(logPath) ) ;
    logger.addDestination(fileDestination.get());


    // Show Qt version.  This is useful for debugging
    QLOG_DEBUG() << "Program Home: " << global.fileManager.getProgramDirPath("");
    QLOG_INFO() << "Built on " << __DATE__ << " at " << __TIME__;
    QLOG_INFO() << "Built with Qt" << QT_VERSION_STR << "running on" << qVersion();
    //QLOG_INFO() << "Thrift version: " << PACKAGE_VERSION;



    // Create a shared memory region.  We use this to communicate
    // with any other instance that may be running.  If another instance
    // is found we need to either show that one or kill this one.
    bool memInitNeeded = true;
    if( !global.sharedMemory->create( 512*1024, QSharedMemory::ReadWrite) ) {
        // Attach to it and detach.  This is done in case it crashed.
        global.sharedMemory->attach();
        global.sharedMemory->detach();
        if( !global.sharedMemory->create( 512*1024, QSharedMemory::ReadWrite) ) {
            if (startupConfig.startupNewNote) {
                global.sharedMemory->attach();
                global.sharedMemory->lock();
                void *dataptr = global.sharedMemory->data();
                memcpy(dataptr, "NEW_NOTE", 8);  // Tell the other guy create a new note
                QLOG_INFO() << "Another NixNote was found.  Requesting it to start another note";
                exit(0);  // Exit this one
            }
            if (startupConfig.startupNoteLid > 0) {
                global.sharedMemory->attach();
                global.sharedMemory->lock();
                void *dataptr = global.sharedMemory->data();
                QString msg = "OPEN_NOTE:" +QString::number(startupConfig.startupNoteLid) + " ";
                memcpy(dataptr, msg.toStdString().c_str(), msg.length());  // Tell the other guy to open a note
                QLOG_INFO() << "Another NixNote was found.  Requesting it to open a note";
                exit(0);  // Exit this one
            }
            // If we've gotten this far, we need to either stop this instance or stop the other
            global.settings->beginGroup("Debugging");
            QString startup = global.settings->value("onMultipleInstances", "SHOW_OTHER").toString();
            global.settings->endGroup();
            global.sharedMemory->attach();
            global.sharedMemory->lock();
            void *dataptr = global.sharedMemory->data();
            if (startup == "SHOW_OTHER") {
                memcpy(dataptr, "SHOW_WINDOW", 11);  // Tell the other guy to show himself
                QLOG_INFO() << "Another NixNote was found.  Stopping this instance";
                exit(0);  // Exit this one
            }
            if (startup == "STOP_OTHER") {
                memcpy(dataptr, "IMMEDIATE_SHUTDOWN", 18);  // Tell the other guy to shut down
                memInitNeeded = false;
            }
            global.sharedMemory->unlock();
        }
    }
    if (memInitNeeded) {
        global.sharedMemory->lock();
        memset(global.sharedMemory->data(), 0, global.sharedMemory->size());
        global.sharedMemory->unlock();
    }



    // Save the clipboard
    global.clipboard = QApplication::clipboard();

    NixNote *w = new NixNote();
    w->setAttribute(Qt::WA_QuitOnClose);
    bool show = true;
    if (global.syncAndExit)
        show = false;
    if (global.minimizeToTray() && global.startMinimized)
        show = false;
    if (show)
        w->show();
    else
        w->hide();
    if (global.startMinimized)
        w->showMinimized();

    // Setup the proxy
    QNetworkProxy proxy;
    proxy.setType(QNetworkProxy::HttpProxy);
    if (global.isProxyEnabled()) {
        QString host = global.getProxyHost();
        int port = global.getProxyPort();
        QString user = global.getProxyUserid();
        QString password = global.getProxyPassword();

        if (host.trimmed() != "")
            proxy.setHostName(host.trimmed());
        if (port > 0)
            proxy.setPort(port);
        if (user.trimmed() != "")
            proxy.setUser(user.trimmed());
        if (password.trimmed() != "")
            proxy.setPassword(password.trimmed());

        QNetworkProxy::setApplicationProxy(proxy);
    }

    int rc = a->exec();
    QLOG_DEBUG() << "Unlocking memory";
    global.sharedMemory->unlock();
    QLOG_DEBUG() << "Deleting NixNote instance";
    delete w;
    QLOG_DEBUG() << "Quitting application instance";
    a->exit(rc);
    QLOG_DEBUG() << "Deleting application instance";
    delete a;
    QLOG_DEBUG() << "Exiting: RC=" << rc;
    exit(rc);
    return rc;
}