Changeset 139 in tspsg-svn


Ignore:
Timestamp:
Sep 29, 2010, 11:21:46 PM (14 years ago)
Author:
laleppa
Message:

+ Automatically check for updates at the given interval functionality (Windows only at this moment).

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/defaults.h

    r129 r139  
    4242 * \brief Default for "Use native file dialog".
    4343 */
    44 #ifdef Q_OS_WINCE
     44#ifdef Q_OS_WINCE_WM
    4545        #define DEF_USE_NATIVE_DIALOGS false
    4646#else
     
    5151//! Default for "Use translucency effects in Vista/7"
    5252#define DEF_USE_TRANSLUCENCY true
     53//! Default for "Check for updates"
     54#define DEF_CHECK_FOR_UPDATES false
     55//! Default update check interval (in days)
     56#define DEF_UPDATE_CHECK_INTERVAL 30
    5357
    5458//////// TASK
  • trunk/src/globals.h

    r137 r139  
    114114}
    115115
     116/*!
     117 * \brief Checks whether the updater app is installed/available.
     118 * \return \c true if updater app is available, oherwise \c false.
     119 * \note The updater app is only available under Windows at this moment.
     120 *  On other systems this function always returns \c false.
     121 */
     122inline bool hasUpdater()
     123{
     124#ifdef Q_OS_WIN32
     125        return QFile::exists("updater/Update.exe");
     126#else // Q_OS_WIN32
     127        return false;
     128#endif // Q_OS_WIN32
     129}
     130
    116131#ifdef Q_OS_WIN32
    117132/*!
  • trunk/src/main.cpp

    r136 r139  
    3737//              Q_IMPORT_PLUGIN(qsvgicon)
    3838//      #endif
    39 //      Q_IMPORT_PLUGIN(qjpeg)
    40 //      Q_IMPORT_PLUGIN(qtiff)
    4139//#endif
    4240
  • trunk/src/mainwindow.cpp

    r138 r139  
    8181#endif // HANDHELD
    8282        connect(actionSettingsPreferences, SIGNAL(triggered()), SLOT(actionSettingsPreferencesTriggered()));
    83 #ifdef Q_OS_WIN32
    84         connect(actionHelpCheck4Updates, SIGNAL(triggered()), SLOT(actionHelpCheck4UpdatesTriggered()));
    85 #endif // Q_OS_WIN32
     83        if (actionHelpCheck4Updates != NULL)
     84                connect(actionHelpCheck4Updates, SIGNAL(triggered()), SLOT(actionHelpCheck4UpdatesTriggered()));
    8685        connect(actionSettingsLanguageAutodetect, SIGNAL(triggered(bool)), SLOT(actionSettingsLanguageAutodetectTriggered(bool)));
    8786        connect(groupSettingsLanguageList, SIGNAL(triggered(QAction *)), SLOT(groupSettingsLanguageListTriggered(QAction *)));
     
    123122        }
    124123        setWindowModified(false);
     124
     125        if ((actionHelpCheck4Updates != NULL)
     126                && (settings->value("Check4Updates/Enabled", DEF_CHECK_FOR_UPDATES).toBool())
     127                && (QDate(qvariant_cast<QDate>(settings->value("Check4Updates/LastAttempt"))).daysTo(QDate::currentDate()) >= settings->value("Check4Updates/Interval", DEF_UPDATE_CHECK_INTERVAL).toInt())) {
     128                check4Updates(true);
     129        }
    125130}
    126131
     
    430435#endif // HANDHELD
    431436
    432 #ifdef Q_OS_WIN32
    433437void MainWindow::actionHelpCheck4UpdatesTriggered()
    434438{
     
    438442        }
    439443
    440         QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    441         QProcess::execute("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\"");
    442         QApplication::restoreOverrideCursor();
    443 }
    444 #endif // Q_OS_WIN32
     444        check4Updates();
     445}
    445446
    446447void MainWindow::actionHelpAboutTriggered()
     
    10401041}
    10411042
     1043void MainWindow::check4Updates(bool silent)
     1044{
     1045#ifdef Q_OS_WIN32
     1046        if (silent)
     1047                QProcess::startDetached("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\" -silentcheck");
     1048        else {
     1049                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     1050                QProcess::execute("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\"");
     1051                QApplication::restoreOverrideCursor();
     1052        }
     1053#endif
     1054        settings->setValue("Check4Updates/LastAttempt", QDate::currentDate().toString(Qt::ISODate));
     1055}
     1056
    10421057void MainWindow::closeEvent(QCloseEvent *ev)
    10431058{
     
    11411156                ev->accept();
    11421157        }
    1143 }
    1144 
    1145 bool MainWindow::hasUpdater() const
    1146 {
    1147 #ifdef Q_OS_WIN32
    1148         return QFile::exists("updater/Update.exe");
    1149 #else // Q_OS_WIN32
    1150         return false;
    1151 #endif // Q_OS_WIN32
    11521158}
    11531159
     
    14441450#endif // HANDHELD
    14451451
    1446 #ifdef Q_OS_WIN32
    1447         actionHelpCheck4Updates->setText(tr("Check for &Updates..."));
     1452        if (actionHelpCheck4Updates != NULL) {
     1453                actionHelpCheck4Updates->setText(tr("Check for &Updates..."));
    14481454#ifndef QT_NO_STATUSTIP
    1449         actionHelpCheck4Updates->setStatusTip(tr("Check for %1 updates").arg(QApplication::applicationName()));
     1455                actionHelpCheck4Updates->setStatusTip(tr("Check for %1 updates").arg(QApplication::applicationName()));
    14501456#endif // QT_NO_STATUSTIP
    1451 #endif // Q_OS_WIN32
     1457        }
    14521458}
    14531459
     
    15931599#endif // HANDHELD
    15941600
    1595 #ifdef Q_OS_WIN32
    1596         actionHelpCheck4Updates = new QAction(this);
    1597         actionHelpCheck4Updates->setIcon(GET_ICON("system-software-update"));
    1598         actionHelpCheck4Updates->setEnabled(hasUpdater());
    1599         menuHelp->insertAction(actionHelpAboutQt, actionHelpCheck4Updates);
    1600         menuHelp->insertSeparator(actionHelpAboutQt);
    1601 #endif // Q_OS_WIN32
     1601        if (hasUpdater()) {
     1602                actionHelpCheck4Updates = new QAction(this);
     1603                actionHelpCheck4Updates->setIcon(GET_ICON("system-software-update"));
     1604                actionHelpCheck4Updates->setEnabled(hasUpdater());
     1605                menuHelp->insertAction(actionHelpAboutQt, actionHelpCheck4Updates);
     1606                menuHelp->insertSeparator(actionHelpAboutQt);
     1607        } else
     1608                actionHelpCheck4Updates = NULL;
    16021609
    16031610        spinCities->setMaximum(MAX_NUM_CITIES);
  • trunk/src/mainwindow.h

    r124 r139  
    7474        void actionSettingsToolbarsConfigureTriggered();
    7575#endif // HANDHELD
    76 #ifdef Q_OS_WIN32
    7776        void actionHelpCheck4UpdatesTriggered();
    78 #endif // Q_OS_WIN32
    7977        void actionHelpAboutTriggered();
    8078// Buttons
     
    111109        QAction *actionFilePrint;
    112110#endif // QT_NO_PRINTER
    113 #ifdef Q_OS_WIN32
    114111        QAction *actionHelpCheck4Updates;
    115 #endif // Q_OS_WIN32
    116112        QSettings *settings;
    117113        CTSPModel *tspmodel;
     
    136132                fmt_altlist;
    137133
     134        void check4Updates(bool silent = false);
    138135        void closeEvent(QCloseEvent *ev);
    139136        void dragEnterEvent(QDragEnterEvent *ev);
    140137        void drawNode(QPainter &pic, int nstep, bool left = false, SStep *step = NULL);
    141138        void dropEvent(QDropEvent *ev);
    142         bool hasUpdater() const;
    143139        void initDocStyleSheet();
    144140        void loadLangList();
  • trunk/src/settingsdialog.cpp

    r135 r139  
    7272        connect(cbShowGraph, SIGNAL(toggled(bool)), cbHQGraph, SLOT(setEnabled(bool)));
    7373#endif
     74
     75        if (hasUpdater()) {
     76                cbCheck4Updates = new QCheckBox(bgWhite);
     77                cbCheck4Updates->setObjectName("cbCheck4Updates");
     78#ifndef QT_NO_STATUSTIP
     79                cbCheck4Updates->setStatusTip(tr("Automatically check for updates at the given interval"));
     80#endif // QT_NO_STATUSTIP
     81                cbCheck4Updates->setText(tr("Check for updates every"));
     82                cbCheck4Updates->setCursor(QCursor(Qt::PointingHandCursor));
     83
     84                spinUpdateCheckInterval = new QSpinBox(bgWhite);
     85                spinUpdateCheckInterval->setObjectName("spinUpdateCheckInterval");
     86#ifndef QT_NO_STATUSTIP
     87                spinUpdateCheckInterval->setStatusTip(tr("Minimal interval at which to check for updates"));
     88#endif // QT_NO_STATUSTIP
     89                spinUpdateCheckInterval->setSuffix(tr(" days", "Don't forget a space at the beginning!"));
     90                spinUpdateCheckInterval->setRange(1, 365);
     91                spinUpdateCheckInterval->setCursor(QCursor(Qt::PointingHandCursor));
     92
     93                connect(cbCheck4Updates, SIGNAL(toggled(bool)), spinUpdateCheckInterval, SLOT(setEnabled(bool)));
     94
     95                box = static_cast<QBoxLayout *>(tabGeneral->layout());
     96                hbox1 = new QHBoxLayout();
     97                hbox1->setSpacing(0);
     98                hbox1->addWidget(cbCheck4Updates);
     99                hbox1->addWidget(spinUpdateCheckInterval);
     100                hbox1->addStretch();
     101                box->insertLayout(box->indexOf(cbUseNativeDialogs) + 1, hbox1);
     102        } else
     103                cbCheck4Updates = NULL;
    74104
    75105#ifdef HANDHELD
     
    209239        cbSaveState->setChecked(settings->value("SavePos", DEF_SAVEPOS).toBool());
    210240#endif // HANDHELD
     241        if (cbCheck4Updates != NULL) {
     242                settings->beginGroup("Check4Updates");
     243                cbCheck4Updates->setChecked(settings->value("Enabled", DEF_CHECK_FOR_UPDATES).toBool());
     244                spinUpdateCheckInterval->setValue(settings->value("Interval", DEF_UPDATE_CHECK_INTERVAL).toInt());
     245                settings->endGroup();
     246                spinUpdateCheckInterval->setEnabled(cbCheck4Updates->isChecked());
     247        }
    211248
    212249        settings->beginGroup("Task");
     
    231268        comboGraphImageFormat->addItem("svg");
    232269#endif // NOSVG && QT_VERSION >= 0x040500
    233 // We create a whitelist of formats, supported by the most popular web browsers according to
    234 //  http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support
    235 //  + TIFF format (there are plugins to support it).
     270        // We create whitelist of formats, supported by the most popular web browsers according to
     271        //  http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support
     272        //  + TIFF format (there are plugins to support it).
    236273QStringList whitelist;
    237274        whitelist << "bmp" << "jpeg" << "png" << "tiff" << "xbm";
     
    327364        settings->setValue("SavePos", cbSaveState->isChecked());
    328365#endif // HANDHELD
     366        if (cbCheck4Updates != NULL) {
     367                settings->beginGroup("Check4Updates");
     368                settings->setValue("Enabled", cbCheck4Updates->isChecked());
     369                if (cbCheck4Updates->isChecked())
     370                        settings->setValue("Interval", spinUpdateCheckInterval->value());
     371                settings->endGroup();
     372        }
    329373
    330374        settings->beginGroup("Task");
  • trunk/src/settingsdialog.h

    r127 r139  
    5959        QCheckBox *cbUseTranslucency;
    6060#endif // Q_OS_WIN32
     61        QCheckBox *cbCheck4Updates;
     62        QSpinBox *spinUpdateCheckInterval;
    6163#ifndef QT_NO_PRINTER
    6264        QCheckBox *cbHQGraph;
  • trunk/tspsg.pri

    r137 r139  
    44#  Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name>
    55#
    6 #  $Id$
    7 #  $URL$
     6#  $Id: tspsg.pri 137 2010-09-15 14:57:37Z laleppa $
     7#  $URL: https://svn.tspsg.info/svnroot/tspsg/trunk/tspsg.pri $
    88#
    99#  This file is part of TSPSG.
     
    4646}
    4747
     48win* {
     49        RC_FILE = resources/tspsg.rc
     50}
     51
    4852#Translations
    4953CODECFORTR = UTF-8
     
    6064        HEADERS += src/_.h
    6165}
     66
  • trunk/tspsg.pro

    r138 r139  
    2020
    2121# QMAKE_MAC_SDK = /Developer/SDKs/MacOSX10.5.sdk
     22
     23# Version information
     24QMAKE_TARGET_COMPANY = Oleksii "Lёppa" Serdiuk
     25QMAKE_TARGET_PRODUCT = TSP Solver and Generator
     26QMAKE_TARGET_DESCRIPTION = TSPSG: TSP Solver and Generator
     27QMAKE_TARGET_COPYRIGHT = Copyright © 2007-2010 Oleksii "Lёppa" Serdiuk <contacts[at]oleksii[dot]name>
    2228
    2329# Versioning
     
    6470        # We "embed" SVG icon, JPEG and TIFF support on static build
    6571        DEFINES += STATIC_BUILD
    66 #       QTPLUGIN += qjpeg qtiff
    6772#       !nosvg:QTPLUGIN += qsvgicon
    6873}
Note: See TracChangeset for help on using the changeset viewer.