00001
00002
00003
00004
00005
00006
00007
#include <qobjectlist.h>
00008
#include <qpixmap.h>
00009
#include <qtimer.h>
00010
#include <qtooltip.h>
00011
#include <ksystemtray.h>
00012
#include <kwin.h>
00013
00014
#include "kwindowinfo.h"
00015
#include "kwindowinfo.moc"
00016
00017
static const int UNSPECIFIED_TIMEOUT = -1;
00018
static const int DEFAULT_MESSAGE_TIMEOUT = 3000;
00019
00020 KWindowInfo::KWindowInfo(
QWidget *parent,
const char *name )
00021 :
QObject( parent, name ), win( parent ), autoDel( false )
00022 {
00023 }
00024
00025 KWindowInfo::~KWindowInfo()
00026 {
00027 }
00028
00029 void KWindowInfo::showMessage(
QWidget *window,
const QString &text,
int timeout )
00030 {
00031
KWindowInfo *info =
new KWindowInfo( window );
00032 info->
autoDel =
true;
00033 info->
message( text, timeout );
00034
if ( timeout == 0 )
00035
delete info;
00036 }
00037
00038 void KWindowInfo::showMessage(
QWidget *window,
const QString &text,
const QPixmap &pix,
int timeout )
00039 {
00040
KWindowInfo *info =
new KWindowInfo( window );
00041 info->
autoDel =
true;
00042 info->
message( text, pix, timeout );
00043 }
00044
00045 void KWindowInfo::message(
const QString &text )
00046 {
00047
message( text,
QPixmap(), UNSPECIFIED_TIMEOUT );
00048 }
00049
00050 void KWindowInfo::message(
const QString &text,
const QPixmap &pix )
00051 {
00052
message( text, pix, UNSPECIFIED_TIMEOUT );
00053 }
00054
00055 void KWindowInfo::message(
const QString &text,
int timeout )
00056 {
00057
message( text,
QPixmap(), timeout );
00058 }
00059
00060 void KWindowInfo::message(
const QString &text,
const QPixmap &pix,
int timeout )
00061 {
00062
if ( timeout != 0 )
00063
save();
00064
00065
display( text, pix );
00066
00067
if ( timeout < 0 )
00068 timeout = DEFAULT_MESSAGE_TIMEOUT;
00069
if ( timeout != 0 )
00070 QTimer::singleShot( timeout,
this, SLOT(
restore() ) );
00071 }
00072
00073 void KWindowInfo::permanent(
const QString &text )
00074 {
00075 oldMiniIcon = KWin::icon( win->
winId(), 16, 16,
true );
00076 oldIcon = KWin::icon( win->
winId(), 34, 34,
false );
00077
if ( oldIcon.
isNull() )
00078 oldIcon = KWin::icon( win->
winId(), 32, 32,
true );
00079
00080
permanent( text, oldIcon );
00081 }
00082
00083 void KWindowInfo::permanent(
const QString &text,
const QPixmap &pix )
00084 {
00085
if ( !oldText.
isNull() ) {
00086
QObjectList *l = queryList(
"QTimer" );
00087 QObjectListIt it( *l );
00088
QObject *obj;
00089
00090
while ( (obj = it.current()) != 0 ) {
00091 ++it;
00092
delete obj;
00093 }
00094
delete l;
00095 }
00096
00097 oldText = QString::null;
00098
display( text, pix );
00099 }
00100
00101 void KWindowInfo::display(
const QString &text,
const QPixmap &pix )
00102 {
00103
QPixmap icon;
00104
if ( pix.
isNull() )
00105 icon.
load(
"bell.png" );
00106
else
00107 icon = pix;
00108
00109
if ( win->inherits(
"KSystemTray" ) ) {
00110
KSystemTray *tray = static_cast<KSystemTray *>( win );
00111 tray->
setPixmap( icon );
00112 QToolTip::add( tray, text );
00113
return;
00114 }
00115
00116 win->
setCaption( text );
00117 win->
setIcon( icon );
00118 KWin::setIcons( win->
winId(), icon, icon );
00119 }
00120
00121 void KWindowInfo::save()
00122 {
00123
if ( !oldText.
isNull() )
00124
return;
00125
00126
if ( win->inherits(
"KSystemTray" ) ) {
00127
KSystemTray *tray = static_cast<KSystemTray *>( win );
00128 oldIcon = *(tray->
pixmap());
00129 oldText = QToolTip::textFor( tray );
00130
return;
00131 }
00132
00133 oldText = win->
caption();
00134 oldMiniIcon = KWin::icon( win->
winId(), 16, 16,
true );
00135 oldIcon = KWin::icon( win->
winId(), 34, 34,
false );
00136
if ( oldIcon.
isNull() )
00137 oldIcon = KWin::icon( win->
winId(), 32, 32,
true );
00138
00139
if ( oldIcon.
isNull() ) {
00140
const QPixmap *px = win->
icon();
00141
if ( px )
00142 oldIcon = *px;
00143
else
00144 oldIcon.
resize( 0, 0 );
00145 }
00146 }
00147
00148 void KWindowInfo::restore()
00149 {
00150
if ( win->inherits(
"KSystemTray" ) ) {
00151
KSystemTray *tray = static_cast<KSystemTray *>( win );
00152 tray->
setPixmap( oldIcon );
00153 QToolTip::add( tray, oldText );
00154 oldText = QString::null;
00155
return;
00156 }
00157
00158 win->
setIcon( oldIcon );
00159 KWin::setIcons( win->
winId(), oldIcon, oldMiniIcon );
00160 win->
setCaption( oldText );
00161 oldText = QString::null;
00162
00163
if ( autoDel )
00164
delete this;
00165 }
00166
00167
00168
00169
00170