1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*-
/* This file is part of the KDE project
Copyright (C) by Andrew Stanley-Jones
Copyright (C) 2000 by Carsten Pfeiffer <pfeiffer@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "applet.h"
#include <tdeaboutapplication.h>
#include <tdeglobal.h>
#include <tdelocale.h>
#include <dcopclient.h>
#include <tdeconfig.h>
#include "toplevel.h"
#include "history.h"
#include "klipperpopup.h"
extern "C"
{
KDE_EXPORT KPanelApplet* init(TQWidget *parent, const TQString& configFile)
{
TDEGlobal::locale()->insertCatalogue("klipper");
int actions = KPanelApplet::Preferences | KPanelApplet::About | KPanelApplet::Help;
return new KlipperApplet(configFile, KPanelApplet::Normal, actions, parent, "klipper");
}
}
KlipperApplet::KlipperApplet(const TQString& configFile, Type t, int actions,
TQWidget *parent, const char *name)
: KPanelApplet(configFile, t, actions, parent, name)
{
KlipperWidget::createAboutData();
move( 0, 0 );
setBackgroundMode(TQWidget::X11ParentRelative);
widget = new KlipperAppletWidget( this );
setCustomMenu(widget->history()->popup());
centerWidget();
widget->show();
}
KlipperApplet::~KlipperApplet()
{
widget->saveSession();
delete widget;
KlipperWidget::destroyAboutData();
}
int KlipperApplet::widthForHeight(int) const
{
return widget->width();
}
int KlipperApplet::heightForWidth(int) const
{
return widget->height();
}
void KlipperApplet::resizeEvent( TQResizeEvent* ev )
{
widget->adjustSize();
KPanelApplet::resizeEvent( ev );
centerWidget();
}
void KlipperApplet::centerWidget()
{
int x = (width() - widget->width())/2;
int y = (height() - widget->height())/2;
widget->move( x, y );
}
void KlipperApplet::preferences()
{
widget->slotConfigure();
}
void KlipperApplet::help()
{
kapp->invokeHelp(TQString::null, TQString::fromLatin1("klipper"));
}
void KlipperApplet::about()
{
TDEAboutApplication about(this, 0);
about.exec();
}
KlipperAppletWidget::KlipperAppletWidget( TQWidget* parent )
// init() is called first, before KlipperWidget is called with ( parent, tdeconfig )
: KlipperWidget( ( init(), parent ), new TDEConfig( "klipperrc" ))
{
}
// this needs to be called before KlipperWidget ctor, because it performs already some
// operations with the clipboard, and the other running instance could notice that
// and request data while this instance is waiting in the DCOP call
void KlipperAppletWidget::init()
{
// if there's klipper process running, quit it
TQByteArray arg1, arg2;
TQCString str;
// call() - wait for finishing
kapp->dcopClient()->call("klipper", "klipper", "quitProcess()", arg1, str, arg2 );
// register ourselves, so if klipper process is started,
// it will quit immediately (KUniqueApplication)
s_dcop = new DCOPClient;
s_dcop->registerAs( "klipper", false );
}
KlipperAppletWidget::~KlipperAppletWidget()
{
delete s_dcop;
s_dcop = 0;
}
DCOPClient* KlipperAppletWidget::s_dcop = 0;
// this is just to make klipper process think we're KUniqueApplication
// (AKA ugly hack)
int KlipperAppletWidget::newInstance()
{
return 0;
}
#include "applet.moc"
|