Changeset 42


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

Trayicon popup menu

Files:
5 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; 
  • gui/main_window.h

    r40 r42  
    2121    public: 
    2222        MainWindow(QWidget *parent = 0); 
    23         //~MainWindow(); 
    2423 
    2524    protected: 
     
    3736        QIcon icon; 
    3837 
    39         void setupTrayIcon(); 
     38        bool setupTrayIcon(); 
    4039        QAction *minimizeAction; 
    4140        QAction *maximizeAction; 
  • gui/preferences_dialog.cpp

    r30 r42  
    77 
    88    connect(buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonPressed(QAbstractButton *))); 
    9  
    109    loadSettings(); 
    1110} 
     
    1716    passwordLineEdit->setText(settings.value("connection/password", "").toString()); 
    1817    systemTrayCheckBox->setChecked(settings.value("systemtray").toBool()); 
     18    if (settings.value("systemtray").toBool()) { 
     19        systemTrayPopup->setChecked(settings.value("systemtrayPopup").toBool()); 
     20    } else { 
     21        systemTrayPopup->setEnabled(false); 
     22    } 
    1923} 
    2024 
     
    3236            settings.setValue("connection/password", passwordLineEdit->text()); 
    3337            settings.setValue("systemtray", systemTrayCheckBox->isChecked()); 
     38            if (systemTrayCheckBox->isChecked()) { 
     39                settings.setValue("systemtrayPopup", systemTrayPopup->isChecked()); 
     40            } else { 
     41                settings.setValue("systemtrayPopup", false); 
     42            } 
    3443            emit systemTraySet(systemTrayCheckBox->isChecked()); 
    3544            break; 
  • gui/preferences_dialog.ui

    r29 r42  
    66    <x>0</x> 
    77    <y>0</y> 
    8     <width>411</width> 
    9     <height>217</height> 
     8    <width>451</width> 
     9    <height>283</height> 
    1010   </rect> 
    1111  </property> 
     
    1313   <string>QtMPC Preferences</string> 
    1414  </property> 
    15   <layout class="QVBoxLayout" > 
    16    <item> 
    17     <layout class="QHBoxLayout" > 
    18      <item> 
    19       <widget class="QLabel" name="label" > 
    20        <property name="text" > 
    21         <string>MPD host:</string> 
    22        </property> 
    23       </widget> 
    24      </item> 
    25      <item> 
    26       <widget class="QLineEdit" name="hostLineEdit" /> 
    27      </item> 
    28     </layout> 
    29    </item> 
    30    <item> 
    31     <layout class="QHBoxLayout" > 
    32      <item> 
    33       <widget class="QLabel" name="label_2" > 
    34        <property name="text" > 
    35         <string>MPD port:</string> 
    36        </property> 
    37       </widget> 
    38      </item> 
    39      <item> 
    40       <widget class="QSpinBox" name="portSpinBox" > 
    41        <property name="minimum" > 
    42         <number>1</number> 
    43        </property> 
    44        <property name="maximum" > 
    45         <number>60000</number> 
    46        </property> 
    47        <property name="value" > 
    48         <number>6600</number> 
    49        </property> 
    50       </widget> 
    51      </item> 
    52     </layout> 
    53    </item> 
    54    <item> 
    55     <layout class="QHBoxLayout" > 
    56      <item> 
    57       <widget class="QLabel" name="label_3" > 
    58        <property name="text" > 
    59         <string>Password:</string> 
    60        </property> 
    61       </widget> 
    62      </item> 
    63      <item> 
    64       <widget class="QLineEdit" name="passwordLineEdit" /> 
    65      </item> 
    66     </layout> 
    67    </item> 
    68    <item> 
    69     <layout class="QHBoxLayout" > 
    70      <item> 
    71       <spacer> 
    72        <property name="orientation" > 
    73         <enum>Qt::Horizontal</enum> 
    74        </property> 
    75        <property name="sizeHint" > 
    76         <size> 
    77          <width>30</width> 
    78          <height>20</height> 
    79         </size> 
    80        </property> 
    81       </spacer> 
    82      </item> 
    83      <item> 
    84       <widget class="QCheckBox" name="connectCheckBox" > 
    85        <property name="enabled" > 
    86         <bool>false</bool> 
    87        </property> 
    88        <property name="text" > 
    89         <string>Connect on Startup</string> 
    90        </property> 
    91       </widget> 
    92      </item> 
    93     </layout> 
    94    </item> 
    95    <item> 
    96     <layout class="QHBoxLayout" > 
    97      <item> 
    98       <spacer> 
    99        <property name="orientation" > 
    100         <enum>Qt::Horizontal</enum> 
    101        </property> 
    102        <property name="sizeHint" > 
    103         <size> 
    104          <width>30</width> 
    105          <height>20</height> 
    106         </size> 
    107        </property> 
    108       </spacer> 
    109      </item> 
    110      <item> 
    111       <widget class="QCheckBox" name="systemTrayCheckBox" > 
    112        <property name="enabled" > 
    113         <bool>true</bool> 
    114        </property> 
    115        <property name="text" > 
    116         <string>Show in System tray</string> 
    117        </property> 
    118       </widget> 
    119      </item> 
    120     </layout> 
    121    </item> 
    122    <item> 
    123     <widget class="QDialogButtonBox" name="buttonBox" > 
    124      <property name="orientation" > 
    125       <enum>Qt::Horizontal</enum> 
    126      </property> 
    127      <property name="standardButtons" > 
    128       <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> 
    129      </property> 
    130     </widget> 
    131    </item> 
    132   </layout> 
     15  <widget class="QDialogButtonBox" name="buttonBox" > 
     16   <property name="geometry" > 
     17    <rect> 
     18     <x>9</x> 
     19     <y>247</y> 
     20     <width>433</width> 
     21     <height>27</height> 
     22    </rect> 
     23   </property> 
     24   <property name="orientation" > 
     25    <enum>Qt::Horizontal</enum> 
     26   </property> 
     27   <property name="standardButtons" > 
     28    <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> 
     29   </property> 
     30  </widget> 
     31  <widget class="QWidget" name="" > 
     32   <property name="geometry" > 
     33    <rect> 
     34     <x>9</x> 
     35     <y>9</y> 
     36     <width>431</width> 
     37     <height>221</height> 
     38    </rect> 
     39   </property> 
     40   <layout class="QVBoxLayout" > 
     41    <item> 
     42     <layout class="QHBoxLayout" > 
     43      <item> 
     44       <widget class="QLabel" name="label" > 
     45        <property name="text" > 
     46         <string>MPD host:</string> 
     47        </property> 
     48       </widget> 
     49      </item> 
     50      <item> 
     51       <widget class="QLineEdit" name="hostLineEdit" /> 
     52      </item> 
     53     </layout> 
     54    </item> 
     55    <item> 
     56     <layout class="QHBoxLayout" > 
     57      <item> 
     58       <widget class="QLabel" name="label_2" > 
     59        <property name="text" > 
     60         <string>MPD port:</string> 
     61        </property> 
     62       </widget> 
     63      </item> 
     64      <item> 
     65       <widget class="QSpinBox" name="portSpinBox" > 
     66        <property name="minimum" > 
     67         <number>1</number> 
     68        </property> 
     69        <property name="maximum" > 
     70         <number>60000</number> 
     71        </property> 
     72        <property name="value" > 
     73         <number>6600</number> 
     74        </property> 
     75       </widget> 
     76      </item> 
     77     </layout> 
     78    </item> 
     79    <item> 
     80     <layout class="QHBoxLayout" > 
     81      <item> 
     82       <widget class="QLabel" name="label_3" > 
     83        <property name="text" > 
     84         <string>Password:</string> 
     85        </property> 
     86       </widget> 
     87      </item> 
     88      <item> 
     89       <widget class="QLineEdit" name="passwordLineEdit" /> 
     90      </item> 
     91     </layout> 
     92    </item> 
     93    <item> 
     94     <layout class="QHBoxLayout" > 
     95      <item> 
     96       <spacer> 
     97        <property name="orientation" > 
     98         <enum>Qt::Horizontal</enum> 
     99        </property> 
     100        <property name="sizeHint" > 
     101         <size> 
     102          <width>30</width> 
     103          <height>20</height> 
     104         </size> 
     105        </property> 
     106       </spacer> 
     107      </item> 
     108      <item> 
     109       <widget class="QCheckBox" name="connectCheckBox" > 
     110        <property name="enabled" > 
     111         <bool>false</bool> 
     112        </property> 
     113        <property name="text" > 
     114         <string>Connect on Startup</string> 
     115        </property> 
     116       </widget> 
     117      </item> 
     118     </layout> 
     119    </item> 
     120    <item> 
     121     <layout class="QHBoxLayout" > 
     122      <item> 
     123       <spacer> 
     124        <property name="orientation" > 
     125         <enum>Qt::Horizontal</enum> 
     126        </property> 
     127        <property name="sizeHint" > 
     128         <size> 
     129          <width>30</width> 
     130          <height>20</height> 
     131         </size> 
     132        </property> 
     133       </spacer> 
     134      </item> 
     135      <item> 
     136       <widget class="QCheckBox" name="systemTrayCheckBox" > 
     137        <property name="enabled" > 
     138         <bool>true</bool> 
     139        </property> 
     140        <property name="text" > 
     141         <string>Show in System tray</string> 
     142        </property> 
     143       </widget> 
     144      </item> 
     145     </layout> 
     146    </item> 
     147    <item> 
     148     <layout class="QHBoxLayout" > 
     149      <item> 
     150       <spacer> 
     151        <property name="orientation" > 
     152         <enum>Qt::Horizontal</enum> 
     153        </property> 
     154        <property name="sizeHint" > 
     155         <size> 
     156          <width>171</width> 
     157          <height>35</height> 
     158         </size> 
     159        </property> 
     160       </spacer> 
     161      </item> 
     162      <item> 
     163       <widget class="QCheckBox" name="systemTrayPopup" > 
     164        <property name="text" > 
     165         <string>Show Popup message</string> 
     166        </property> 
     167       </widget> 
     168      </item> 
     169     </layout> 
     170    </item> 
     171   </layout> 
     172  </widget> 
    133173 </widget> 
    134174 <resources/> 
     
    166206   </hints> 
    167207  </connection> 
     208  <connection> 
     209   <sender>systemTrayCheckBox</sender> 
     210   <signal>clicked(bool)</signal> 
     211   <receiver>systemTrayPopup</receiver> 
     212   <slot>setEnabled(bool)</slot> 
     213   <hints> 
     214    <hint type="sourcelabel" > 
     215     <x>363</x> 
     216     <y>173</y> 
     217    </hint> 
     218    <hint type="destinationlabel" > 
     219     <x>360</x> 
     220     <y>209</y> 
     221    </hint> 
     222   </hints> 
     223  </connection> 
    168224 </connections> 
    169225</ui> 
  • main.cpp

    r29 r42  
    1111    QApplication::setOrganizationName("lowblogprojects"); 
    1212 
    13     if (!QSystemTrayIcon::isSystemTrayAvailable()) { 
    14         QMessageBox::critical(0, QObject::tr("Systray"), 
    15             QObject::tr("I couldn't detect any system tray on this system.")); 
    16         return 1; 
    17     } 
    18  
    1913    MainWindow w; 
    2014    w.show(); 
Note: See TracChangeset for help on using the changeset viewer.