28 #include <tqtooltip.h>
31 #include <tqtextedit.h>
34 #include <dcopclient.h>
36 #include <tdeapplication.h>
38 #include <tdeglobal.h>
39 #include <tdeglobalsettings.h>
40 #include <kiconloader.h>
41 #include <tdelocale.h>
42 #include <kurllabel.h>
43 #include <kdialogbase.h>
44 #include <tdemessagebox.h>
46 #include "pilotDaemonDCOP_stub.h"
48 #include <ktextedit.h>
50 #include "summarywidget.h"
52 SummaryWidget::SummaryWidget( TQWidget *parent,
const char *name )
53 : Kontact::Summary( parent, name ),
54 DCOPObject(
"KPilotSummaryWidget" ),
55 mDCOPSuccess( false ),
56 mStartedDaemon( false ),
57 mShouldStopDaemon( true )
59 mLayout =
new TQGridLayout(
this, 2, 3, 3, 3 );
62 TQPixmap icon = TDEGlobal::iconLoader()->loadIcon(
"kpilot", TDEIcon::Desktop, TDEIcon::SizeMedium );
63 TQWidget *header = createHeader(
this, icon, i18n(
"KPilot Configuration" ) );
64 mLayout->addMultiCellWidget( header, row,row, 0,3 );
68 mSyncTimeTextLabel =
new TQLabel( i18n(
"<i>Last sync:</i>" ),
this);
69 mLayout->addWidget( mSyncTimeTextLabel, row, 0 );
70 mSyncTimeLabel =
new TQLabel( i18n(
"No information available" ),
this );
71 mLayout->addWidget( mSyncTimeLabel, row, 1 );
72 mShowSyncLogLabel =
new KURLLabel(
"", i18n(
"[View Sync Log]" ),
this );
73 mLayout->addWidget( mShowSyncLogLabel, row, 3 );
74 connect( mShowSyncLogLabel, TQ_SIGNAL( leftClickedURL(
const TQString& ) ),
75 this, TQ_SLOT( showSyncLog(
const TQString& ) ) );
79 mPilotUserTextLabel =
new TQLabel( i18n(
"<i>User:</i>" ),
this);
80 mLayout->addWidget( mPilotUserTextLabel, row, 0);
81 mPilotUserLabel =
new TQLabel( i18n(
"Unknown" ),
this );
82 mLayout->addMultiCellWidget( mPilotUserLabel, row, row, 1, 3 );
86 mPilotDeviceTextLabel =
new TQLabel( i18n(
"<i>Device:</i>" ),
this);
87 mLayout->addWidget( mPilotDeviceTextLabel, row, 0 );
88 mPilotDeviceLabel =
new TQLabel( i18n(
"Unknown" ),
this );
89 mLayout->addMultiCellWidget( mPilotDeviceLabel, row, row, 1, 3 );
93 mDaemonStatusTextLabel =
new TQLabel( i18n(
"<i>Status:</i>" ),
this);
94 mLayout->addWidget( mDaemonStatusTextLabel, row, 0 );
95 mDaemonStatusLabel =
new TQLabel( i18n(
"No communication with the daemon possible" ),
this );
96 mLayout->addMultiCellWidget( mDaemonStatusLabel, row, row, 1, 3 );
100 mConduitsTextLabel =
new TQLabel( i18n(
"<i>Conduits:</i>" ),
this );
101 mConduitsTextLabel->setAlignment( AlignAuto | AlignTop | ExpandTabs );
102 mLayout->addWidget( mConduitsTextLabel, row, 0 );
103 mConduitsLabel =
new TQLabel( i18n(
"No information available" ),
this );
104 mConduitsLabel->setAlignment( mConduitsLabel->alignment() | TQt::WordBreak );
105 mLayout->addMultiCellWidget( mConduitsLabel, row, row, 1, 3 );
109 mNoConnectionLabel =
new TQLabel( i18n(
"KPilot is currently not running." ),
this );
110 mLayout->addMultiCellWidget( mNoConnectionLabel, row, row, 1, 2 );
111 mNoConnectionStartLabel =
new KURLLabel(
"", i18n(
"[Start KPilot]" ),
this );
112 mLayout->addWidget( mNoConnectionStartLabel, row, 3 );
113 connect( mNoConnectionStartLabel, TQ_SIGNAL( leftClickedURL(
const TQString& ) ),
114 this, TQ_SLOT( startKPilot() ) );
116 if ( !kapp->dcopClient()->isApplicationRegistered(
"kpilotDaemon" ) ) {
120 connectDCOPSignal( 0, 0,
"kpilotDaemonStatusDetails(TQDateTime,TQString,TQStringList,TQString,TQString,TQString,bool)",
121 "receiveDaemonStatusDetails(TQDateTime,TQString,TQStringList,TQString,TQString,TQString,bool)",
false );
122 connect( kapp->dcopClient(), TQ_SIGNAL( applicationRemoved(
const TQCString & ) ), TQ_SLOT( slotAppRemoved(
const TQCString& ) ) );
125 SummaryWidget::~SummaryWidget()
127 if ( mStartedDaemon && mShouldStopDaemon ) {
128 PilotDaemonDCOP_stub dcopToDaemon(
"kpilotDaemon",
"KPilotDaemonIface" );
129 dcopToDaemon.quitNow();
133 TQStringList SummaryWidget::configModules()
const
135 TQStringList modules;
136 modules <<
"kpilot_config.desktop";
140 void SummaryWidget::receiveDaemonStatusDetails(TQDateTime lastSyncTime, TQString status, TQStringList conduits, TQString logFileName, TQString userName, TQString pilotDevice,
bool killOnExit )
143 mLastSyncTime = lastSyncTime;
144 mDaemonStatus = status;
145 mConduits = conduits;
146 mSyncLog = logFileName;
147 mUserName = userName;
148 mPilotDevice = pilotDevice;
149 mShouldStopDaemon = killOnExit;
153 void SummaryWidget::updateView()
155 if ( mDCOPSuccess ) {
156 if ( mLastSyncTime.isValid() ) {
157 mSyncTimeLabel->setText( mLastSyncTime.toString(TQt::LocalDate) );
159 mSyncTimeLabel->setText( i18n(
"No information available" ) );
161 if ( !mSyncLog.isEmpty() ) {
162 mShowSyncLogLabel->setEnabled(
true );
163 mShowSyncLogLabel->setURL( mSyncLog );
165 mShowSyncLogLabel->setEnabled(
false );
167 mPilotUserLabel->setText( mUserName.isEmpty() ? i18n(
"unknown" ) : mUserName );
168 mPilotDeviceLabel->setText( mPilotDevice.isEmpty() ? i18n(
"unknown" ) : mPilotDevice );
169 mDaemonStatusLabel->setText( mDaemonStatus );
170 mConduitsLabel->setText( mConduits.join(
", " ) );
172 mSyncTimeLabel->setText( i18n(
"No information available (Daemon not running?)" ) );
173 mShowSyncLogLabel->setEnabled(
false );
174 mPilotUserLabel->setText( i18n(
"unknown" ) );
175 mPilotDeviceLabel->setText( i18n(
"unknown" ) );
176 mDaemonStatusLabel->setText( i18n(
"No communication with the daemon possible" ) );
177 mConduitsLabel->setText( i18n(
"No information available" ) );
180 mSyncTimeTextLabel->setShown( mDCOPSuccess );
181 mSyncTimeLabel->setShown( mDCOPSuccess );
182 mShowSyncLogLabel->setShown( mDCOPSuccess );
183 mPilotUserTextLabel->setShown( mDCOPSuccess );
184 mPilotUserLabel->setShown( mDCOPSuccess );
185 mPilotDeviceTextLabel->setShown( mDCOPSuccess );
186 mPilotDeviceLabel->setShown( mDCOPSuccess );
187 mDaemonStatusTextLabel->setShown( mDCOPSuccess );
188 mDaemonStatusLabel->setShown( mDCOPSuccess );
189 mConduitsTextLabel->setShown( mDCOPSuccess );
190 mConduitsLabel->setShown( mDCOPSuccess );
191 mNoConnectionLabel->setShown( !mDCOPSuccess );
192 mNoConnectionStartLabel->setShown( !mDCOPSuccess );
195 void SummaryWidget::showSyncLog(
const TQString &filename )
197 KDialogBase dlg(
this, 0,
true, TQString(), KDialogBase::Ok, KDialogBase::Ok );
198 dlg.setCaption( i18n(
"KPilot HotSync Log" ) );
200 TQTextEdit *edit =
new TQTextEdit( dlg.makeVBoxMainWidget() );
201 edit->setReadOnly(
true );
204 if ( !f.open( IO_ReadOnly ) ) {
205 KMessageBox::error(
this, i18n(
"Unable to open Hotsync log %1." ).arg( filename ) );
209 TQTextStream s( &f );
211 edit->append( s.readLine() );
213 edit->moveCursor( TQTextEdit::MoveHome,
false );
217 dlg.setInitialSize( TQSize( 400, 350 ) );
221 void SummaryWidget::startKPilot()
225 if ( !TDEApplication::tdeinitExec(
"kpilotDaemon", TQString(
"--fail-silently" ) ) ) {
226 kdDebug(5602) <<
"No service available..." << endl;
227 mStartedDaemon =
true;
231 void SummaryWidget::slotAppRemoved(
const TQCString & appId )
233 if ( appId ==
"kpilotDaemon" )
235 mDCOPSuccess =
false;
241 #include "summarywidget.moc"