00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qimage.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qtooltip.h>
00029 #include <qfile.h>
00030 #include <qlabel.h>
00031 #include <qtextedit.h>
00032 #include <qvbox.h>
00033
00034 #include <dcopclient.h>
00035 #include <dcopref.h>
00036 #include <kapplication.h>
00037 #include <kdebug.h>
00038 #include <kglobal.h>
00039 #include <kglobalsettings.h>
00040 #include <kiconloader.h>
00041 #include <klocale.h>
00042 #include <kurllabel.h>
00043 #include <kdialogbase.h>
00044 #include <kmessagebox.h>
00045
00046 #include "pilotDaemonDCOP_stub.h"
00047
00048 #include <ktextedit.h>
00049
00050
00051 #include "summarywidget.h"
00052
00053 SummaryWidget::SummaryWidget( QWidget *parent, const char *name )
00054 : Kontact::Summary( parent, name ),
00055 DCOPObject( "KPilotSummaryWidget" ),
00056 mDCOPSuccess(false),
00057 mStartedDaemon(false),
00058 mShouldStopDaemon(true)
00059 {
00060 mLayout = new QGridLayout( this );
00061
00062 int row=0;
00063 QPixmap icon = KGlobal::iconLoader()->loadIcon( "kpilot", KIcon::Desktop, KIcon::SizeMedium );
00064 QWidget *header = createHeader( this, icon, i18n( "KPilot Information" ) );
00065 mLayout->addMultiCellWidget( header, row,row, 0,3 );
00066
00067
00068 row++;
00069 mLayout->addWidget( new QLabel( i18n("<i>Last sync:</i>"), this), row, 0 );
00070 mSyncTimeLabel = new QLabel( i18n("No information available" ), this );
00071 mLayout->addWidget( mSyncTimeLabel, row, 1 );
00072 mShowSyncLogLabel = new KURLLabel( "", i18n("[log]"), this );
00073 mLayout->addWidget( mShowSyncLogLabel, row, 3 );
00074 connect( mShowSyncLogLabel, SIGNAL( leftClickedURL( const QString& ) ),
00075 this, SLOT( showSyncLog( const QString& ) ) );
00076
00077
00078 row++;
00079 mLayout->addWidget( new QLabel( i18n("<i>User:</i>"), this), row, 0);
00080 mPilotUserLabel = new QLabel( i18n("Unknown"), this );
00081 mLayout->addMultiCellWidget( mPilotUserLabel, row, row, 1,3 );
00082
00083
00084 row++;
00085 mLayout->addWidget( new QLabel( i18n("<i>Device:</i>"), this), row, 0 );
00086 mPilotDeviceLabel = new QLabel( i18n("Unknown"), this );
00087 mLayout->addMultiCellWidget( mPilotDeviceLabel, row, row, 1,3 );
00088
00089
00090 row++;
00091 mLayout->addWidget( new QLabel( i18n("<i>Status:</i>"), this), row, 0);
00092 mDaemonStatusLabel = new QLabel( i18n("No communication with the daemon possible"), this );
00093 mLayout->addMultiCellWidget( mDaemonStatusLabel, row, row, 1,3 );
00094
00095
00096 row++;
00097 QLabel *l = new QLabel( i18n("<i>Conduits:</i>"), this );
00098 l->setAlignment(AlignAuto | AlignTop | ExpandTabs);
00099 mLayout->addWidget( l, row, 0 );
00100 mConduitsLabel = new QLabel( i18n("No information available"), this );
00101 mConduitsLabel->setAlignment( mConduitsLabel->alignment()|Qt::WordBreak );
00102 mLayout->addMultiCellWidget( mConduitsLabel, row,row, 1,3 );
00103
00104
00105
00106
00107 QString error;
00108 QCString appID;
00109
00110 if ( !kapp->dcopClient()->isApplicationRegistered( "kpilotDaemon" ) ) {
00111 if ( !KApplication::startServiceByDesktopName( "kpilotDaemon", QString( "--fail-silently" ),
00112 &error, &appID ) ) {
00113 kdDebug(5602) << "No service available..." << endl;
00114 mStartedDaemon = true;
00115 }
00116 }
00117
00118 connectDCOPSignal( 0, 0, "kpilotDaemonStatusChanged()", "refresh()", false );
00119 refresh();
00120 }
00121
00122 SummaryWidget::~SummaryWidget()
00123 {
00124 if (mStartedDaemon && mShouldStopDaemon)
00125 {
00126 PilotDaemonDCOP_stub dcopToDaemon( "kpilotDaemon", "KPilotDaemonIface" );
00127 dcopToDaemon.quitNow();
00128 }
00129 }
00130
00131 QStringList SummaryWidget::configModules() const
00132 {
00133 QStringList modules;
00134 modules << "kpilot_config.desktop";
00135 return modules;
00136 }
00137
00138 void SummaryWidget::refresh( )
00139 {
00140 PilotDaemonDCOP_stub dcopToDaemon( "kpilotDaemon", "KPilotDaemonIface" );
00141 mDCOPSuccess = true;
00142
00143 mLastSyncTime = dcopToDaemon.lastSyncDate();
00144
00145 mDCOPSuccess = mDCOPSuccess && dcopToDaemon.ok();
00146
00147 mDaemonStatus = dcopToDaemon.shortStatusString();
00148 mDCOPSuccess = mDCOPSuccess && dcopToDaemon.ok();
00149
00150 mConduits = dcopToDaemon.configuredConduitList();
00151 mDCOPSuccess = mDCOPSuccess && dcopToDaemon.ok();
00152
00153 mSyncLog = dcopToDaemon.logFileName();
00154 mDCOPSuccess = mDCOPSuccess && dcopToDaemon.ok();
00155
00156 mUserName = dcopToDaemon.userName();
00157 mDCOPSuccess = mDCOPSuccess && dcopToDaemon.ok();
00158
00159 mPilotDevice = dcopToDaemon.pilotDevice();
00160 mDCOPSuccess = mDCOPSuccess && dcopToDaemon.ok();
00161
00162 mShouldStopDaemon = dcopToDaemon.killDaemonOnExit();
00163 mDCOPSuccess = mDCOPSuccess && dcopToDaemon.ok();
00164
00165 updateView();
00166 }
00167
00168
00169 void SummaryWidget::updateView()
00170 {
00171 if (mDCOPSuccess)
00172 {
00173 if ( mLastSyncTime.isValid() ) {
00174 mSyncTimeLabel->setText( mLastSyncTime.toString(Qt::LocalDate) );
00175 } else {
00176 mSyncTimeLabel->setText( i18n("No information available") );
00177 }
00178 if (!mSyncLog.isEmpty()) {
00179 mShowSyncLogLabel->setEnabled(true);
00180 mShowSyncLogLabel->setURL( mSyncLog );
00181 } else {
00182 mShowSyncLogLabel->setEnabled(false);
00183 }
00184 mPilotUserLabel->setText( (mUserName.isEmpty())?i18n("unknown"):mUserName );
00185 mPilotDeviceLabel->setText( (mPilotDevice.isEmpty())?i18n("unknown"):mPilotDevice );
00186 mDaemonStatusLabel->setText( mDaemonStatus );
00187 mConduitsLabel->setText( mConduits.join(", ") );
00188 }
00189 else
00190 {
00191 mSyncTimeLabel->setText( i18n("No information available (Daemon not running?)" ) );
00192 mShowSyncLogLabel->setEnabled(false);
00193 mPilotUserLabel->setText( i18n("unknown" ) );
00194 mPilotDeviceLabel->setText( i18n("unknown" ) );
00195 mDaemonStatusLabel->setText( i18n("No communication with the daemon possible") );
00196 mConduitsLabel->setText( i18n("No information available") );
00197 }
00198 }
00199
00200 void SummaryWidget::showSyncLog( const QString &filename )
00201 {
00202 KDialogBase dlg( this, 0, true, QString::null, KDialogBase::Ok, KDialogBase::Ok );
00203 dlg.setCaption( i18n("KPilot HotSync Log") );
00204 QTextEdit *edit = new QTextEdit( dlg.makeVBoxMainWidget() );
00205 edit->setReadOnly(TRUE);
00206
00207
00208 QFile f(filename);
00209 if (!f.open(IO_ReadOnly))
00210 {
00211 KMessageBox::error( this, i18n("Unable to open Hotsync log %1.").arg(filename) );
00212 return;
00213 }
00214
00215 QTextStream s(&f);
00216 while (!s.eof()) edit->append(s.readLine());
00217
00218 edit->moveCursor(QTextEdit::MoveHome, false);
00219
00220 f.close();
00221
00222 dlg.setInitialSize( QSize( 400, 350) );
00223 dlg.exec();
00224 }
00225 #include "summarywidget.moc"