view ui/mainwindow.cpp @ 15:95e1b6edf2fc

Implement more downloader functionality for Windows
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 19 Feb 2014 10:45:06 +0000
parents 7e2f14c7aba2
children 225a5ec20dad
line wrap: on
line source
#include "mainwindow.h"

#include <QDebug>
#include <QMessageBox>
#include <QSystemTrayIcon>
#include <QAction>
#include <QDialog>
#include <QMenu>
#include <QApplication>

#include "certificatelist.h"
#include "downloader.h"

MainWindow::MainWindow() {
    createActions();
    createTrayIcon();

    connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
}

void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
    showMessage();
    qDebug() << "Activated for reason: " << reason;
    switch (reason) {
    case QSystemTrayIcon::Trigger:
    case QSystemTrayIcon::DoubleClick:
    case QSystemTrayIcon::MiddleClick:
        showMessage();
        break;
    default:
        ;
    }
}

void MainWindow::showMessage()
{
    mTrayIcon->showMessage("Hello", "World", QSystemTrayIcon::Information,
                          10000);
}
void MainWindow::manualCheck()
{
    Downloader* downloader = new Downloader(this, QString::fromLatin1(""));
    connect(downloader, &Downloader::finished, downloader, &QObject::deleteLater);
    downloader->start();
}

void MainWindow::createActions()
{
    mCheckUpdates = new QAction(tr("Check for Updates"), this);
    connect(mCheckUpdates, SIGNAL(triggered()), this, SLOT(manualCheck()));
    mQuitAction = new QAction(tr("Quit"), this);
    connect(mQuitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}

void MainWindow::createTrayIcon()
{
    QIcon trayImg(":/img/tray_22.png");

    mTrayMenu = new QMenu(this);
    mTrayMenu->addAction(mCheckUpdates);
    mTrayMenu->addAction(mQuitAction);

    mTrayIcon = new QSystemTrayIcon(this);
    mTrayIcon->setContextMenu(mTrayMenu);

    mTrayIcon->setIcon(trayImg);
    setWindowIcon(trayImg);
    mTrayIcon->show();
    mTrayIcon->setToolTip(tr("m13ui"));
    showMessage();
}

http://wald.intevation.org/projects/trustbridge/