view ui/mainwindow.cpp @ 11:7e2f14c7aba2

Split up downloader component and further implement it
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 14 Feb 2014 11:20:15 +0000
parents fe39d93f1261
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/