summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kde2file/abdump/main.cpp5
-rw-r--r--libkdepim/ksyncmanager.cpp14
2 files changed, 16 insertions, 3 deletions
diff --git a/kde2file/abdump/main.cpp b/kde2file/abdump/main.cpp
index 9ad78e5..b359cfe 100644
--- a/kde2file/abdump/main.cpp
+++ b/kde2file/abdump/main.cpp
@@ -1,193 +1,196 @@
/*******************************************************************************
* main.cpp *
* *
*
* *
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* As a special exception, permission is given to link this program *
* with any edition of Qt, and distribute the resulting executable, *
* without including the source code for Qt in the source distribution. *
* *
******************************************************************************/
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include <kglobal.h>
#include <kconfig.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <kabc/addressbook.h>
#include <kabc/stdaddressbook.h>
#include <kabc/resource.h>
#include <kabc/vcardconverter.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qdir.h>
#include <qapplication.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
static const char progName[] = "kdecalendar";
static const char progDisplay[] = "KDE_Addressbook";
static const char progVersion[] = "33.1/3";
static const char progDesc[] = "A command line interface to KDE addressbooks";
static KCmdLineOptions options[] =
{
{ "dump",
I18N_NOOP( "Dumps addressbook" ), 0 },
{ "read",
I18N_NOOP( "Reads addressbook" ), 0 },
KCmdLineLastOption
};
int main( int argc, char *argv[] )
{
KAboutData aboutData(
progName, // internal program name
I18N_NOOP( progDisplay ), // displayable program name.
progVersion, // version string
I18N_NOOP( progDesc ), // short porgram description
KAboutData::License_GPL, // license type
"(c) 2004, Lutz Rogowski", // copyright statement
0, // any free form text
"", // program home page address
"bugs.kde.org" // bug report email address
);
// KCmdLineArgs::init() final 'true' argument indicates no commandline options
// for QApplication/KApplication (no KDE or Qt options)
KCmdLineArgs::init( argc, argv, &aboutData, true );
KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
KInstance ins ( progName );
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
bool read = false;
if ( args->isSet( "read" ) ) {
read = true;
qDebug("read ");
}
QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
KABC::StdAddressBook* standardAddressBook = KABC::StdAddressBook::self();
standardAddressBook->setAutomaticSave( false );
qDebug("************************************* ");
qDebug("***************kdeABdump************* ");
qDebug("************************************* ");
if ( !read ) {
KABC::AddressBook::Iterator it;
KABC::VCardConverter converter;
QString datastream;
for( it = standardAddressBook->begin(); it != standardAddressBook->end(); ++it ) {
if ( (*it).isEmpty() || ! (*it).resource() )
continue;
KABC::Addressee a = ( *it );
QString vcard = converter.createVCard( a );
vcard += QString("\r\n");
datastream += vcard;
}
QFile outFile(fileName);
if ( outFile.open(IO_WriteOnly) ) {
QTextStream t( &outFile ); // use a text stream
t.setEncoding( QTextStream::UnicodeUTF8 );
t <<datastream;
t << "\r\n\r\n";
outFile.close();
}
} else {
//Addressee::List aList;//parseVCards( const QString& vcard );
KABC::Addressee::List list;
int added = 0, changedC = 0, deleted = 0;
QFile file( fileName );
if ( file.open( IO_ReadOnly ) ) {
QTextStream t( &file ); // use a text stream
t.setEncoding( QTextStream::UnicodeUTF8 );
QString data;
data = t.read();
file.close();
KABC::VCardConverter converter;
list = converter.parseVCards( data );
qDebug("kdeABdump::file has %d entries", list.count());
KABC::Addressee::List::Iterator it;
for ( it = list.begin();it != list.end();++it) {
(*it).setChanged( true );
bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed");
(*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
//qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1());
if ( changed ) {
//qDebug("changed Addressee found! ");
KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() );
if ( ! std.isEmpty() )
(*it).setResource(std.resource());
standardAddressBook->insertAddressee( (*it) );
++changedC;
} else {
//maybe added?
KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() );
if ( std.isEmpty() ) {
standardAddressBook->insertAddressee( (*it) );
++added;
}
}
}
KABC::AddressBook::Iterator itA = standardAddressBook->begin();
KABC::AddressBook::Iterator it2 ;
while ( itA != standardAddressBook->end() ) {
bool found = false;
KABC::Addressee::List::Iterator itL;
for ( itL = list.begin();itL != list.end();++itL) {
if ( (*itL).uid() == (*itA).uid() ) {
found = true;
break;
}
}
if ( !found ) {
it2 = itA;
++itA;
standardAddressBook->removeAddressee( it2 );
++deleted;
} else {
++itA;
}
}
//standardAddressBook->saveAll();
standardAddressBook->setAutomaticSave( true );
qDebug("************************************* ");
qDebug("*************kdeABdump*************** ");
qDebug("************************************* ");
qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1());
} else
qDebug("error open file ");
}
+ standardAddressBook->close();
+ // line not needed by KDE 3.4:
+ // delete standardAddressBook;
+
- delete standardAddressBook;
//KABC::StdAddressBook::close();
//StdAddressBook::mSelf = 0;
qDebug("ente ");
return 0;
}
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index d59f4a4..7319285 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -733,405 +733,415 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
// 0 : okay
// 256: no such file or dir
//
qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result );
if ( result != 0 ) {
unsigned int len = maxlen;
while ( len < preCommand.length() ) {
preCommand.insert( len , "\n" );
len += maxlen +2;
}
question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ;
QMessageBox::information( mParent, i18n("Sync - ERROR"),
question,
i18n("Okay!")) ;
mParent->topLevelWidget()->setCaption ("KDE-Pim");
return;
}
mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
//qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
if ( syncWithFile( localTempFile, true ) ) {
if ( mWriteBackFile ) {
int fi;
if ( (fi = postCommand.find("$PWD$")) > 0 ) {
QString pwd = getPassword();
postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
}
mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
result = system ( postCommand );
qDebug("KSM::Sync:Writing back file result: %d ", result);
if ( result != 0 ) {
mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
return;
} else {
mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
}
}
}
return;
}
bool KSyncManager::edit_pisync_options()
{
QDialog dia( mParent, "dia", true );
dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
QVBoxLayout lay ( &dia );
lay.setSpacing( 5 );
lay.setMargin( 3 );
QLabel lab1 ( i18n("Password for remote access:"), &dia);
lay.addWidget( &lab1 );
QLineEdit le1 (&dia );
lay.addWidget( &le1 );
QLabel lab2 ( i18n("Remote IP address:"), &dia);
lay.addWidget( &lab2 );
QLineEdit le2 (&dia );
lay.addWidget( &le2 );
QLabel lab3 ( i18n("Remote port number:"), &dia);
lay.addWidget( &lab3 );
QLineEdit le3 (&dia );
lay.addWidget( &le3 );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
le1.setText( mPassWordPiSync );
le2.setText( mActiveSyncIP );
le3.setText( mActiveSyncPort );
if ( dia.exec() ) {
mPassWordPiSync = le1.text();
mActiveSyncPort = le3.text();
mActiveSyncIP = le2.text();
return true;
}
return false;
}
bool KSyncManager::edit_sync_options()
{
QDialog dia( mParent, "dia", true );
dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
QVBoxLayout lay ( &dia );
lay.setSpacing( 2 );
lay.setMargin( 3 );
lay.addWidget(&gr);
QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
//QRadioButton both( i18n("Take both on conflict"), &gr );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
switch ( mSyncAlgoPrefs ) {
case 0:
loc.setChecked( true);
break;
case 1:
rem.setChecked( true );
break;
case 2:
newest.setChecked( true);
break;
case 3:
ask.setChecked( true);
break;
case 4:
f_loc.setChecked( true);
break;
case 5:
f_rem.setChecked( true);
break;
case 6:
// both.setChecked( true);
break;
default:
break;
}
if ( dia.exec() ) {
mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
return true;
}
return false;
}
QString KSyncManager::getPassword( )
{
QString retfile = "";
QDialog dia ( mParent, "input-dialog", true );
QLineEdit lab ( &dia );
lab.setEchoMode( QLineEdit::Password );
QVBoxLayout lay( &dia );
lay.setMargin(7);
lay.setSpacing(7);
lay.addWidget( &lab);
dia.setFixedSize( 230,50 );
dia.setCaption( i18n("Enter password") );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
dia.show();
int res = dia.exec();
if ( res )
retfile = lab.text();
dia.hide();
qApp->processEvents();
return retfile;
}
void KSyncManager::confSync()
{
static KSyncPrefsDialog* sp = 0;
if ( ! sp ) {
sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
}
sp->usrReadConfig();
#ifndef DESKTOP_VERSION
sp->showMaximized();
#else
sp->show();
#endif
sp->exec();
QStringList oldSyncProfileNames = mSyncProfileNames;
mSyncProfileNames = sp->getSyncProfileNames();
mLocalMachineName = sp->getLocalMachineName ();
int ii;
for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
}
QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
}
void KSyncManager::syncKDE()
{
mSyncWithDesktop = true;
emit save();
switch(mTargetApp)
{
case (KAPI):
{
#ifdef DESKTOP_VERSION
QString command = qApp->applicationDirPath () + "/kdeabdump";
#else
QString command = "kdeabdump";
#endif
if ( ! QFile::exists ( command ) )
command = "kdeabdump";
QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
- system ( command.latin1());
+ int result = system ( command.latin1());
+ qDebug("AB dump command call result: %d ", result);
+ if ( result != 0 ) {
+ KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n/opt/kdepimpi/kdeabdump\nexists.The standard version of this file\nis for syncing with KDE 3.4.x.\nIf you are running KDE 3.3.x please\ndownload the KDE 3.3.x version of this file\nat http://sourceforge.net/projects/kdepimpi/\nsection: general files for KDE/Pim."));
+ return;
+ }
if ( syncWithFile( fileName,true ) ) {
if ( mWriteBackFile ) {
command += " --read";
system ( command.latin1());
}
}
}
break;
case (KOPI):
{
#ifdef DESKTOP_VERSION
QString command = qApp->applicationDirPath () + "/kdecaldump";
#else
QString command = "kdecaldump";
#endif
if ( ! QFile::exists ( command ) )
command = "kdecaldump";
QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
- system ( command.latin1());
+ int result = system ( command.latin1());
+ qDebug("Cal dump command call result result: %d ", result);
+ if ( result != 0 ) {
+ KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n/opt/kdepimpi/kdecaldump\nexists.The standard version of this file\nis for syncing with KDE 3.4.x.\nIf you are running KDE 3.3.x please\ndownload the KDE 3.3.x version of this file\nat http://sourceforge.net/projects/kdepimpi/\nsection: general files for KDE/Pim."));
+ return;
+ }
if ( syncWithFile( fileName,true ) ) {
if ( mWriteBackFile ) {
command += " --read";
system ( command.latin1());
}
}
}
break;
case (PWMPI):
break;
default:
qDebug("KSM::slotSyncMenu: invalid apptype selected");
break;
}
}
void KSyncManager::syncSharp()
{
if ( ! syncExternalApplication("sharp") )
qDebug("KSM::ERROR sync sharp ");
}
bool KSyncManager::syncExternalApplication(QString resource)
{
emit save();
if ( mAskForPreferences )
if ( !edit_sync_options()) {
mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
return false;
}
qDebug("KSM::Sync extern %s", resource.latin1());
bool syncOK = mImplementation->syncExternal(this, resource);
return syncOK;
}
void KSyncManager::syncPhone()
{
syncExternalApplication("phone");
}
void KSyncManager::showProgressBar(int percentage, QString caption, int total)
{
if (!bar->isVisible())
{
bar->setCaption (caption);
bar->setTotalSteps ( total ) ;
bar->show();
}
bar->raise();
bar->setProgress( percentage );
qApp->processEvents();
}
void KSyncManager::hideProgressBar()
{
bar->hide();
qApp->processEvents();
}
bool KSyncManager::isProgressBarCanceled()
{
return !bar->isVisible();
}
QString KSyncManager::syncFileName()
{
QString fn = "tempfile";
switch(mTargetApp)
{
case (KAPI):
fn = "tempsyncab.vcf";
break;
case (KOPI):
fn = "tempsynccal.ics";
break;
case (PWMPI):
fn = "tempsyncpw.pwm";
break;
default:
break;
}
#ifdef _WIN32_
return locateLocal( "tmp", fn );
#else
return (QString( "/tmp/" )+ fn );
#endif
}
void KSyncManager::syncPi()
{
mIsKapiFile = true;
mPisyncFinished = false;
qApp->processEvents();
if ( mAskForPreferences )
if ( !edit_pisync_options()) {
mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
mPisyncFinished = true;
return;
}
bool ok;
Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
if ( ! ok ) {
mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
mPisyncFinished = true;
return;
}
KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
commandSocket->readFile( syncFileName() );
}
void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
{
//enum { success, errorW, errorR, quiet };
if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW ||
state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) {
if ( state == KCommandSocket::errorPW )
mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") );
else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO )
mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
else if ( state == KCommandSocket::errorCA )
mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") );
else if ( state == KCommandSocket::errorFI )
mParent->topLevelWidget()->setCaption( i18n("File error on remote.") );
else if ( state == KCommandSocket::errorED )
mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") );
else if ( state == KCommandSocket::errorUN )
mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") );
delete s;
if ( state == KCommandSocket::errorR ) {
KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget());
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
commandSocket->sendStop();
}
mPisyncFinished = true;
return;
} else if ( state == KCommandSocket::errorW ) {
mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
mPisyncFinished = true;
} else if ( state == KCommandSocket::successR ) {
QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
} else if ( state == KCommandSocket::successW ) {
mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
mPisyncFinished = true;
} else if ( state == KCommandSocket::quiet ){
qDebug("KSS: quiet ");
mPisyncFinished = true;
} else {
qDebug("KSS: Error: unknown state: %d ", state);
mPisyncFinished = true;
}
delete s;
}
void KSyncManager::readFileFromSocket()
{
QString fileName = syncFileName();
bool syncOK = true;
mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
if ( ! syncWithFile( fileName , true ) ) {
mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
syncOK = false;
}
KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
if ( mWriteBackFile && syncOK )
commandSocket->writeFile( fileName );
else {
commandSocket->sendStop();
if ( syncOK )
mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
mPisyncFinished = true;