~ubuntu-branches/debian/squeeze/smplayer/squeeze

« back to all changes in this revision

Viewing changes to src/baseguiplus.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Breuil Cyril
  • Date: 2007-06-24 16:35:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070624163529-hhckbmd24uicada7
Tags: 0.5.20-0ubuntu1
* New upstream release
* Change Maintainer Email

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include "baseguiplus.h"
20
20
 
 
21
#ifdef USE_SYSTEM_TRAY
 
22
 
21
23
#if QT_VERSION >= 0x040200
22
24
#include <Q3PopupMenu>
 
25
#else
 
26
#include <qpopupmenu.h>
 
27
#include "mysystemtrayicon.h"
 
28
#endif
 
29
 
23
30
#include "myaction.h"
24
31
#include "global.h"
25
32
#include "images.h"
26
 
#include "playlist2.h"
 
33
#include "playlist.h"
27
34
//#include "infowindow.h"
28
35
#endif
29
36
 
30
37
 
31
 
BaseGuiPlus::BaseGuiPlus( QString file, QWidget * parent, const char* name, 
 
38
BaseGuiPlus::BaseGuiPlus( QStringList files, QWidget * parent, const char* name,
32
39
                          WFlags fl )
33
 
        : BaseGui( file, parent, name, fl )
 
40
        : BaseGui( files, parent, name, fl )
34
41
{
35
 
        #if QT_VERSION >= 0x040200
 
42
#ifdef USE_SYSTEM_TRAY
36
43
        mainwindow_visible = true;
37
44
        playlist_visible = false;
38
45
        //infowindow_visible = false;
39
46
        mainwindow_pos = pos();
40
47
 
 
48
        #if QT_VERSION >= 0x040200
41
49
        tray = new QSystemTrayIcon( Images::icon("logo", 22), this );
 
50
        #else
 
51
        tray = new MySystemTrayIcon( Images::icon("logo", 22), this );
 
52
        #endif
 
53
 
42
54
        tray->setToolTip( "SMPlayer" );
43
55
        connect( tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), 
44
56
             this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
45
57
 
 
58
        quitAct = new MyAction(this, "quit");
 
59
    connect( quitAct, SIGNAL(activated()), this, SLOT(quit()) );
46
60
        quitAct->addTo( openMenu );
47
61
 
48
62
        showTrayAct = new MyAction(this, "show_try_icon" );
55
69
        connect( showAllAct, SIGNAL(activated()),
56
70
             this, SLOT(toggleShowAll()) );
57
71
 
58
 
        context_menu = new Q3PopupMenu(this);
 
72
        context_menu = new QPopupMenu(this);
 
73
 
59
74
        showAllAct->addTo( context_menu );
60
 
        context_menu->addSeparator();
 
75
        context_menu->insertSeparator();
61
76
        openFileAct->addTo( context_menu );
62
77
        recents_menu_id = context_menu->insertItem( "Recents", recentfiles_menu );
63
78
        openDVDAct->addTo( context_menu );
64
79
        openURLAct->addTo( context_menu );
65
 
        context_menu->addSeparator();
 
80
        context_menu->insertSeparator();
66
81
        playOrPauseAct->addTo( context_menu );
67
82
        stopAct->addTo( context_menu );
68
 
        context_menu->addSeparator();
69
 
        playlist->playPrevAct()->addTo( context_menu );
70
 
        playlist->playNextAct()->addTo( context_menu );
71
 
        context_menu->addSeparator();
 
83
        context_menu->insertSeparator();
 
84
        playPrevAct->addTo( context_menu );
 
85
        playNextAct->addTo( context_menu );
 
86
        context_menu->insertSeparator();
72
87
        showPlaylistAct->addTo( context_menu );
73
88
        showPreferencesAct->addTo( context_menu );
74
 
        context_menu->addSeparator();
 
89
        context_menu->insertSeparator();
75
90
        quitAct->addTo( context_menu );
76
91
        
77
92
        tray->setContextMenu( context_menu );
78
 
        #endif
 
93
#endif
79
94
 
80
95
        languageChange();
81
96
 
88
103
 
89
104
void BaseGuiPlus::firstShow() {
90
105
        qDebug("BaseGuiPlus::firstShow");
91
 
        #if QT_VERSION >= 0x040200
92
 
        if ( (!showTrayAct->isOn()) || (!initial_file.isEmpty()) || (mainwindow_visible) ) {
 
106
#ifdef USE_SYSTEM_TRAY
 
107
        if ( (!showTrayAct->isOn()) || (!initial_files.empty()) || 
 
108
         (mainwindow_visible) ) 
 
109
        {
93
110
                show();
94
111
        }
95
 
        #else
 
112
#else
96
113
        BaseGui::firstShow();
97
 
        #endif
 
114
#endif
98
115
}
99
116
 
100
117
void BaseGuiPlus::closeEvent( QCloseEvent * e ) {
101
 
        #if QT_VERSION >= 0x040200
 
118
        qDebug("BaseGuiPlus::closeEvent");
 
119
        e->ignore();
 
120
        closeWindow();
 
121
}
 
122
 
 
123
void BaseGuiPlus::closeWindow() {
 
124
        qDebug("BaseGuiPlus::closeWindow");
 
125
#ifdef USE_SYSTEM_TRAY
102
126
        if (tray->isVisible()) {
103
 
                e->ignore();
 
127
                //e->ignore();
 
128
                exitFullscreen();
104
129
                showAll(false); // Hide windows
105
130
                if (core->state == PLAYING) core->stop();
106
 
                tray->showMessage( "SMPlayer", 
107
 
                        tr("SMPlayer is still running here"), 
108
 
            QSystemTrayIcon::Information, 3000 );
 
131
                #if QT_VERSION >= 0x040200
 
132
                if (pref->balloon_count > 0) {
 
133
                        tray->showMessage( "SMPlayer", 
 
134
                                tr("SMPlayer is still running here"), 
 
135
                    QSystemTrayIcon::Information, 3000 );
 
136
                        pref->balloon_count--;
 
137
                }
 
138
                #endif
109
139
        } else {
110
 
                BaseGui::closeEvent(e);
 
140
                BaseGui::closeWindow();
111
141
        }
112
142
        //tray->hide();
113
 
        #else
114
 
        BaseGui::closeEvent(e);
115
 
        #endif
 
143
#else
 
144
        BaseGui::closeWindow();
 
145
#endif
 
146
}
 
147
 
 
148
void BaseGuiPlus::quit() {
 
149
        qDebug("BaseGuiPlus::quit");
 
150
        BaseGui::closeWindow();
116
151
}
117
152
 
118
153
void BaseGuiPlus::languageChange() {
119
154
        BaseGui::languageChange();
120
155
 
121
 
        #if QT_VERSION >= 0x040200
 
156
#ifdef USE_SYSTEM_TRAY
 
157
        quitAct->change( Images::icon("exit"), tr("&Quit") );
122
158
        showTrayAct->change( tr("S&how icon in system tray") );
123
159
        context_menu->changeItem( recents_menu_id, tr("&Recent files") );
124
160
        updateShowAllAct();
125
 
        #endif
 
161
#endif
126
162
}
127
163
 
128
164
void BaseGuiPlus::updateShowAllAct() {
129
 
        #if QT_VERSION >= 0x040200
 
165
#ifdef USE_SYSTEM_TRAY
130
166
        if (isVisible()) 
131
167
                showAllAct->change( tr("&Hide") );
132
168
        else
133
169
                showAllAct->change( tr("&Restore") );
134
 
        #endif
 
170
#endif
135
171
}
136
172
 
137
173
void BaseGuiPlus::saveConfig() {
138
174
        qDebug("BaseGuiPlus::saveConfig");
139
175
 
140
 
        #if QT_VERSION >= 0x040200
 
176
#ifdef USE_SYSTEM_TRAY
141
177
 
142
178
        QSettings * set = settings;
143
179
 
148
184
 
149
185
        set->endGroup();
150
186
 
151
 
        #endif
 
187
#endif
152
188
}
153
189
 
154
190
void BaseGuiPlus::loadConfig() {
155
191
        qDebug("BaseGuiPlus::loadConfig");
156
192
 
157
 
        #if QT_VERSION >= 0x040200
 
193
#ifdef USE_SYSTEM_TRAY
158
194
 
159
195
        QSettings * set = settings;
160
196
 
169
205
        set->endGroup();
170
206
 
171
207
        updateShowAllAct();
172
 
        #endif
 
208
#endif
173
209
}
174
210
 
175
211
 
176
212
void BaseGuiPlus::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
177
 
        #if QT_VERSION >= 0x040200
 
213
#ifdef USE_SYSTEM_TRAY
178
214
        qDebug("DefaultGui::trayIconActivated: %d", reason);
179
215
 
180
216
        updateShowAllAct();
182
218
        if (reason == QSystemTrayIcon::Trigger) {
183
219
                toggleShowAll();
184
220
        }
185
 
        #endif
 
221
        else
 
222
        if (reason == QSystemTrayIcon::MiddleClick) {
 
223
                core->pause();
 
224
        }
 
225
#endif
186
226
}
187
227
 
188
228
void BaseGuiPlus::toggleShowAll() {
189
 
        #if QT_VERSION >= 0x040200
 
229
#ifdef USE_SYSTEM_TRAY
190
230
        showAll( !isVisible() );
191
 
        #endif
 
231
#endif
192
232
}
193
233
 
194
234
void BaseGuiPlus::showAll(bool b) {
195
 
        #if QT_VERSION >= 0x040200
 
235
#ifdef USE_SYSTEM_TRAY
196
236
        if (!b) {
197
237
                // Hide all
198
238
                mainwindow_pos = pos();
225
265
                */
226
266
        }
227
267
        updateShowAllAct();
228
 
        #endif
 
268
#endif
229
269
}
230
270
 
231
271
void BaseGuiPlus::resizeWindow(int w, int h) {
232
272
    qDebug("BaseGuiPlus::resizeWindow: %d, %d", w, h);
233
273
 
234
 
        #if QT_VERSION >= 0x040200
 
274
#ifdef USE_SYSTEM_TRAY
235
275
        if ( (tray->isVisible()) && (!isVisible()) ) showAll(true);
236
 
        #endif
 
276
#endif
237
277
 
238
278
        BaseGui::resizeWindow(w, h );
239
279
}
241
281
void BaseGuiPlus::updateMediaInfo() {
242
282
    qDebug("BaseGuiPlus::updateMediaInfo");
243
283
        BaseGui::updateMediaInfo();
244
 
        #if QT_VERSION >= 0x040200
 
284
 
 
285
#ifdef USE_SYSTEM_TRAY
245
286
        tray->setToolTip( caption() );
246
 
        #endif
247
 
}
 
287
#endif
 
288
}
 
289
 
 
290
void BaseGuiPlus::setWindowCaption(const QString & title) {
 
291
#ifdef USE_SYSTEM_TRAY
 
292
        tray->setToolTip( title );
 
293
#endif
 
294
        BaseGui::setWindowCaption( title );
 
295
}
 
296