Changeset 42 for gui/main_window.cpp


Ignore:
Timestamp:
01/07/08 16:25:46 (4 years ago)
Author:
roeland
Message:

Trayicon popup menu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/main_window.cpp

    r41 r42  
    22#include <QtGui> 
    33#include <QIcon> 
    4 #include <QDebug> 
     4#include <QString> 
    55 
    66#include "main_window.h" 
     
    1010MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) 
    1111{ 
     12    //Setup and set visible. 
    1213    setupUi(this); 
     14    setVisible(true); 
    1315 
    1416    slidingVolume = false; 
     
    1921 
    2022    //Tray stuf 
    21     setupTrayIcon(); 
    22     if (settings.value("systemtray").toBool()) { 
     23    if (setupTrayIcon() && settings.value("systemtray").toBool()) { 
    2324        trayIcon->show(); 
    2425    } 
     
    7980} 
    8081 
    81 /*MainWindow::~MainWindow() 
    82 { 
    83     qDebug("Closing main window..."); 
    84 }*/ 
    85  
    8682void MainWindow::closeEvent(QCloseEvent *event) 
    8783{ 
    88     if (trayIcon->isVisible()) { 
    89         QMessageBox::information(this, tr("Systray"), 
    90             tr("The program will keep running in the " 
    91             "system tray. To terminate the program, " 
    92             "choose <b>Quit</b> in the context menu " 
    93             "of the system tray entry.")); 
     84    if (trayIcon != NULL && trayIcon->isVisible()) { 
    9485        hide(); 
    9586        event->ignore(); 
     
    9788} 
    9889 
    99 void MainWindow::setupTrayIcon() 
    100 { 
     90bool MainWindow::setupTrayIcon() 
     91{ 
     92    if (!QSystemTrayIcon::isSystemTrayAvailable()) { 
     93        trayIcon = NULL; 
     94        return false; 
     95    } 
     96 
    10197    trayIcon = new QSystemTrayIcon(this); 
    10298    trayIconMenu = new QMenu(this); 
     
    127123    trayIcon->setIcon(icon); 
    128124    trayIcon->setToolTip("QtMPC"); 
     125     
     126    return true; 
    129127} 
    130128 
     
    132130{ 
    133131    PreferencesDialog pref(this); 
    134     connect(&pref, SIGNAL(systemTraySet(bool)), trayIcon, SLOT(setVisible(bool))); 
     132    if (trayIcon != NULL) 
     133        connect(&pref, SIGNAL(systemTraySet(bool)), trayIcon, SLOT(setVisible(bool))); 
    135134    pref.exec(); 
    136135} 
     
    210209 
    211210    playlistModel.updateCurrentSong(song->id); 
     211 
     212    if (settings.value("systemtrayPopup").toBool() && trayIcon != NULL && trayIcon->isVisible() && isHidden()) { 
     213        if (!song->title.isEmpty() && !song->artist.isEmpty() && !song->album.isEmpty()) { 
     214            trayIcon->showMessage(song->artist + " - " + song->title, 
     215                "album:" + song->album + "\n" +  
     216                "track:" + QString::number(song->track) + "\n" +  
     217                "time:" + QString::number(song->time) + "\n", 
     218                QSystemTrayIcon::Information, 5000); 
     219        } 
     220    } 
    212221 
    213222    delete song; 
Note: See TracChangeset for help on using the changeset viewer.