-rw-r--r-- | core/launcher/systray.cpp | 93 |
1 files changed, 67 insertions, 26 deletions
diff --git a/core/launcher/systray.cpp b/core/launcher/systray.cpp index ad1553f..4767150 100644 --- a/core/launcher/systray.cpp +++ b/core/launcher/systray.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
@@ -39,2 +39,3 @@ SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0) | |||
39 | { | 39 | { |
40 | safety_tid = 0; | ||
40 | //setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 41 | //setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
@@ -43,4 +44,20 @@ SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0) | |||
43 | 44 | ||
45 | static int compareAppletPositions(const void *a, const void *b) | ||
46 | { | ||
47 | const TaskbarApplet* aa = *(const TaskbarApplet**)a; | ||
48 | const TaskbarApplet* ab = *(const TaskbarApplet**)b; | ||
49 | int d = ab->iface->position() - aa->iface->position(); | ||
50 | if ( d ) return d; | ||
51 | return QString::compare(ab->library->library(),aa->library->library()); | ||
52 | } | ||
53 | |||
44 | void SysTray::loadApplets() | 54 | void SysTray::loadApplets() |
45 | { | 55 | { |
56 | clearApplets(); | ||
57 | addApplets(); | ||
58 | } | ||
59 | |||
60 | void SysTray::clearApplets() | ||
61 | { | ||
62 | hide(); | ||
46 | #ifndef SINGLE_APP | 63 | #ifndef SINGLE_APP |
@@ -52,2 +69,3 @@ void SysTray::loadApplets() | |||
52 | } | 69 | } |
70 | #endif | ||
53 | appletList.clear(); | 71 | appletList.clear(); |
@@ -55,3 +73,17 @@ void SysTray::loadApplets() | |||
55 | delete layout; | 73 | delete layout; |
56 | layout = new QHBoxLayout( this ); | 74 | layout = new QHBoxLayout( this, 0, 1 ); |
75 | layout->setAutoAdd(TRUE); | ||
76 | } | ||
77 | |||
78 | void SysTray::addApplets() | ||
79 | { | ||
80 | #ifndef SINGLE_APP | ||
81 | Config cfg( "Taskbar" ); | ||
82 | cfg.setGroup( "Applets" ); | ||
83 | bool safe = cfg.readBoolEntry("SafeMode",FALSE); | ||
84 | if ( safe && !safety_tid ) | ||
85 | return; | ||
86 | cfg.writeEntry("SafeMode",TRUE); | ||
87 | cfg.write(); | ||
88 | QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); | ||
57 | 89 | ||
@@ -61,3 +93,7 @@ void SysTray::loadApplets() | |||
61 | QStringList::Iterator it; | 93 | QStringList::Iterator it; |
94 | int napplets=0; | ||
95 | TaskbarApplet* *applets = new TaskbarApplet*[list.count()]; | ||
62 | for ( it = list.begin(); it != list.end(); ++it ) { | 96 | for ( it = list.begin(); it != list.end(); ++it ) { |
97 | if ( exclude.find( *it ) != exclude.end() ) | ||
98 | continue; | ||
63 | TaskbarAppletInterface *iface = 0; | 99 | TaskbarAppletInterface *iface = 0; |
@@ -65,7 +101,17 @@ void SysTray::loadApplets() | |||
65 | if ( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) { | 101 | if ( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) { |
66 | TaskbarApplet applet; | 102 | TaskbarApplet *applet = new TaskbarApplet; |
67 | applet.library = lib; | 103 | applets[napplets++] = applet; |
68 | applet.iface = iface; | 104 | applet->library = lib; |
69 | applet.applet = applet.iface->applet( this ); | 105 | applet->iface = iface; |
70 | positionApplet( applet ); | 106 | } else { |
107 | exclude += *it; | ||
108 | delete lib; | ||
109 | } | ||
110 | } | ||
111 | cfg.writeEntry( "ExcludeApplets", exclude, ',' ); | ||
112 | qsort(applets,napplets,sizeof(applets[0]),compareAppletPositions); | ||
113 | while (napplets--) { | ||
114 | TaskbarApplet *applet = applets[napplets]; | ||
115 | applet->applet = applet->iface->applet( this ); | ||
116 | appletList.append(*applet); | ||
71 | QString lang = getenv( "LANG" ); | 117 | QString lang = getenv( "LANG" ); |
@@ -74,3 +120,2 @@ void SysTray::loadApplets() | |||
74 | QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; | 120 | QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; |
75 | qDebug("tr fpr sysapplet: %s", tfn.latin1() ); | ||
76 | if ( trans->load( tfn )) | 121 | if ( trans->load( tfn )) |
@@ -79,8 +124,5 @@ void SysTray::loadApplets() | |||
79 | delete trans; | 124 | delete trans; |
80 | } else { | ||
81 | delete lib; | ||
82 | } | ||
83 | } | 125 | } |
126 | delete applets; | ||
84 | #else | 127 | #else |
85 | layout = new QHBoxLayout( this ); | ||
86 | TaskbarApplet applet; | 128 | TaskbarApplet applet; |
@@ -88,20 +130,19 @@ void SysTray::loadApplets() | |||
88 | applet.applet = applet.iface->applet( this ); | 130 | applet.applet = applet.iface->applet( this ); |
89 | positionApplet( applet ); | 131 | appletList.append( a ); |
90 | #endif | 132 | #endif |
133 | show(); | ||
134 | |||
135 | if ( !safety_tid ) | ||
136 | safety_tid = startTimer(2000); // TT has 5000, but this is a PITA for a developer ;) (sandman) | ||
91 | } | 137 | } |
92 | 138 | ||
93 | void SysTray::positionApplet( const TaskbarApplet &a ) | 139 | void SysTray::timerEvent(QTimerEvent* e) |
94 | { | 140 | { |
95 | int p = 0; | 141 | if ( e->timerId() == safety_tid ) { |
96 | QValueList<TaskbarApplet>::Iterator it; | 142 | Config cfg( "Taskbar" ); |
97 | for ( it = appletList.begin(); it != appletList.end(); ++it ) { | 143 | cfg.setGroup( "Applets" ); |
98 | if ( (*it).iface->position() > a.iface->position() ) | 144 | cfg.writeEntry( "SafeMode", FALSE ); |
99 | break; | 145 | killTimer(safety_tid); |
100 | p += 2; | 146 | safety_tid = 0; |
101 | } | 147 | } |
102 | |||
103 | appletList.insert( it, a ); | ||
104 | layout->insertWidget( p, a.applet ); | ||
105 | layout->insertSpacing( p, 1 ); | ||
106 | } | 148 | } |
107 | |||