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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
This file is part of Kontact.
Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
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; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
As a special exception, permission is given to link this program
with any edition of TQt, and distribute the resulting executable,
without including the source code for TQt in the source distribution.
*/
#include <tqimage.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqtooltip.h>
#include <tqfile.h>
#include <tqlabel.h>
#include <tqtextedit.h>
#include <tqvbox.h>
#include <dcopclient.h>
#include <dcopref.h>
#include <tdeapplication.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kglobalsettings.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kurllabel.h>
#include <kdialogbase.h>
#include <kmessagebox.h>
#include "pilotDaemonDCOP_stub.h"
#include <ktextedit.h>
#include "summarywidget.h"
SummaryWidget::SummaryWidget( TQWidget *parent, const char *name )
: Kontact::Summary( parent, name ),
DCOPObject( "KPilotSummaryWidget" ),
mDCOPSuccess( false ),
mStartedDaemon( false ),
mShouldStopDaemon( true )
{
mLayout = new TQGridLayout( this, 2, 3, 3, 3 );
int row=0;
TQPixmap icon = TDEGlobal::iconLoader()->loadIcon( "kpilot", TDEIcon::Desktop, TDEIcon::SizeMedium );
TQWidget *header = createHeader( this, icon, i18n( "KPilot Configuration" ) );
mLayout->addMultiCellWidget( header, row,row, 0,3 );
// Last sync information
row++;
mSyncTimeTextLabel = new TQLabel( i18n( "<i>Last sync:</i>" ), this);
mLayout->addWidget( mSyncTimeTextLabel, row, 0 );
mSyncTimeLabel = new TQLabel( i18n( "No information available" ), this );
mLayout->addWidget( mSyncTimeLabel, row, 1 );
mShowSyncLogLabel = new KURLLabel( "", i18n( "[View Sync Log]" ), this );
mLayout->addWidget( mShowSyncLogLabel, row, 3 );
connect( mShowSyncLogLabel, TQT_SIGNAL( leftClickedURL( const TQString& ) ),
this, TQT_SLOT( showSyncLog( const TQString& ) ) );
// User
row++;
mPilotUserTextLabel = new TQLabel( i18n( "<i>User:</i>" ), this);
mLayout->addWidget( mPilotUserTextLabel, row, 0);
mPilotUserLabel = new TQLabel( i18n( "Unknown" ), this );
mLayout->addMultiCellWidget( mPilotUserLabel, row, row, 1, 3 );
// Device information
row++;
mPilotDeviceTextLabel = new TQLabel( i18n( "<i>Device:</i>" ), this);
mLayout->addWidget( mPilotDeviceTextLabel, row, 0 );
mPilotDeviceLabel = new TQLabel( i18n( "Unknown" ), this );
mLayout->addMultiCellWidget( mPilotDeviceLabel, row, row, 1, 3 );
// Status
row++;
mDaemonStatusTextLabel = new TQLabel( i18n( "<i>Status:</i>" ), this);
mLayout->addWidget( mDaemonStatusTextLabel, row, 0 );
mDaemonStatusLabel = new TQLabel( i18n( "No communication with the daemon possible" ), this );
mLayout->addMultiCellWidget( mDaemonStatusLabel, row, row, 1, 3 );
// Conduits:
row++;
mConduitsTextLabel = new TQLabel( i18n( "<i>Conduits:</i>" ), this );
mConduitsTextLabel->setAlignment( AlignAuto | AlignTop | ExpandTabs );
mLayout->addWidget( mConduitsTextLabel, row, 0 );
mConduitsLabel = new TQLabel( i18n( "No information available" ), this );
mConduitsLabel->setAlignment( mConduitsLabel->alignment() | TQt::WordBreak );
mLayout->addMultiCellWidget( mConduitsLabel, row, row, 1, 3 );
// widgets shown if kpilotDaemon is not running
row++;
mNoConnectionLabel = new TQLabel( i18n( "KPilot is currently not running." ), this );
mLayout->addMultiCellWidget( mNoConnectionLabel, row, row, 1, 2 );
mNoConnectionStartLabel = new KURLLabel( "", i18n( "[Start KPilot]" ), this );
mLayout->addWidget( mNoConnectionStartLabel, row, 3 );
connect( mNoConnectionStartLabel, TQT_SIGNAL( leftClickedURL( const TQString& ) ),
this, TQT_SLOT( startKPilot() ) );
if ( !kapp->dcopClient()->isApplicationRegistered( "kpilotDaemon" ) ) {
startKPilot();
}
connectDCOPSignal( 0, 0, "kpilotDaemonStatusDetails(TQDateTime,TQString,TQStringList,TQString,TQString,TQString,bool)",
"receiveDaemonStatusDetails(TQDateTime,TQString,TQStringList,TQString,TQString,TQString,bool)", false );
connect( kapp->dcopClient(), TQT_SIGNAL( applicationRemoved( const TQCString & ) ), TQT_SLOT( slotAppRemoved( const TQCString& ) ) );
}
SummaryWidget::~SummaryWidget()
{
if ( mStartedDaemon && mShouldStopDaemon ) {
PilotDaemonDCOP_stub dcopToDaemon( "kpilotDaemon", "KPilotDaemonIface" );
dcopToDaemon.quitNow(); // ASYNC, always succeeds.
}
}
TQStringList SummaryWidget::configModules() const
{
TQStringList modules;
modules << "kpilot_config.desktop";
return modules;
}
void SummaryWidget::receiveDaemonStatusDetails(TQDateTime lastSyncTime, TQString status, TQStringList conduits, TQString logFileName, TQString userName, TQString pilotDevice, bool killOnExit )
{
mDCOPSuccess = true;
mLastSyncTime = lastSyncTime;
mDaemonStatus = status;
mConduits = conduits;
mSyncLog = logFileName;
mUserName = userName;
mPilotDevice = pilotDevice;
mShouldStopDaemon = killOnExit;
updateView();
}
void SummaryWidget::updateView()
{
if ( mDCOPSuccess ) {
if ( mLastSyncTime.isValid() ) {
mSyncTimeLabel->setText( mLastSyncTime.toString(TQt::LocalDate) );
} else {
mSyncTimeLabel->setText( i18n( "No information available" ) );
}
if ( !mSyncLog.isEmpty() ) {
mShowSyncLogLabel->setEnabled( true );
mShowSyncLogLabel->setURL( mSyncLog );
} else {
mShowSyncLogLabel->setEnabled( false );
}
mPilotUserLabel->setText( mUserName.isEmpty() ? i18n( "unknown" ) : mUserName );
mPilotDeviceLabel->setText( mPilotDevice.isEmpty() ? i18n( "unknown" ) : mPilotDevice );
mDaemonStatusLabel->setText( mDaemonStatus );
mConduitsLabel->setText( mConduits.join( ", " ) );
} else {
mSyncTimeLabel->setText( i18n( "No information available (Daemon not running?)" ) );
mShowSyncLogLabel->setEnabled( false );
mPilotUserLabel->setText( i18n( "unknown" ) );
mPilotDeviceLabel->setText( i18n( "unknown" ) );
mDaemonStatusLabel->setText( i18n( "No communication with the daemon possible" ) );
mConduitsLabel->setText( i18n( "No information available" ) );
}
mSyncTimeTextLabel->setShown( mDCOPSuccess );
mSyncTimeLabel->setShown( mDCOPSuccess );
mShowSyncLogLabel->setShown( mDCOPSuccess );
mPilotUserTextLabel->setShown( mDCOPSuccess );
mPilotUserLabel->setShown( mDCOPSuccess );
mPilotDeviceTextLabel->setShown( mDCOPSuccess );
mPilotDeviceLabel->setShown( mDCOPSuccess );
mDaemonStatusTextLabel->setShown( mDCOPSuccess );
mDaemonStatusLabel->setShown( mDCOPSuccess );
mConduitsTextLabel->setShown( mDCOPSuccess );
mConduitsLabel->setShown( mDCOPSuccess );
mNoConnectionLabel->setShown( !mDCOPSuccess );
mNoConnectionStartLabel->setShown( !mDCOPSuccess );
}
void SummaryWidget::showSyncLog( const TQString &filename )
{
KDialogBase dlg( this, 0, true, TQString(), KDialogBase::Ok, KDialogBase::Ok );
dlg.setCaption( i18n( "KPilot HotSync Log" ) );
TQTextEdit *edit = new TQTextEdit( dlg.makeVBoxMainWidget() );
edit->setReadOnly( true );
TQFile f(filename);
if ( !f.open( IO_ReadOnly ) ) {
KMessageBox::error( this, i18n( "Unable to open Hotsync log %1." ).arg( filename ) );
return;
}
TQTextStream s( &f );
while ( !s.eof() )
edit->append( s.readLine() );
edit->moveCursor( TQTextEdit::MoveHome, false );
f.close();
dlg.setInitialSize( TQSize( 400, 350 ) );
dlg.exec();
}
void SummaryWidget::startKPilot()
{
TQString error;
TQCString appID;
if ( !TDEApplication::tdeinitExec( "kpilotDaemon", TQString( "--fail-silently" ) ) ) {
kdDebug(5602) << "No service available..." << endl;
mStartedDaemon = true;
}
}
void SummaryWidget::slotAppRemoved( const TQCString & appId )
{
if ( appId == "kpilotDaemon" )
{
mDCOPSuccess = false;
updateView();
}
}
#include "summarywidget.moc"
|