author | zautrix <zautrix> | 2004-12-05 13:41:41 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-12-05 13:41:41 (UTC) |
commit | 06bebf5be01898145c4f721a8d002519141e7f3b (patch) (unidiff) | |
tree | bc44d996a58a63de8c43cb5ba54d55bf1494eb5c | |
parent | 5ab47964d8b52897bb0662ef4a5fcf9604acaf6c (diff) | |
download | kdepimpi-06bebf5be01898145c4f721a8d002519141e7f3b.zip kdepimpi-06bebf5be01898145c4f721a8d002519141e7f3b.tar.gz kdepimpi-06bebf5be01898145c4f721a8d002519141e7f3b.tar.bz2 |
added better debug output to sync file problems
-rw-r--r-- | kaddressbook/kabcore.cpp | 8 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 15cab73..b7edccd 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -1413,769 +1413,771 @@ void KABCore::setDetailsVisible( bool visible ) | |||
1413 | if ( addrList.count() > 0 ) | 1413 | if ( addrList.count() > 0 ) |
1414 | mDetails->setAddressee( addrList[ 0 ] ); | 1414 | mDetails->setAddressee( addrList[ 0 ] ); |
1415 | } | 1415 | } |
1416 | 1416 | ||
1417 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between | 1417 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between |
1418 | // the listview and the detailview. We do that by changing the splitbar size. | 1418 | // the listview and the detailview. We do that by changing the splitbar size. |
1419 | if (mMultipleViewsAtOnce) | 1419 | if (mMultipleViewsAtOnce) |
1420 | { | 1420 | { |
1421 | if ( visible ) | 1421 | if ( visible ) |
1422 | mDetails->show(); | 1422 | mDetails->show(); |
1423 | else | 1423 | else |
1424 | mDetails->hide(); | 1424 | mDetails->hide(); |
1425 | } | 1425 | } |
1426 | else | 1426 | else |
1427 | { | 1427 | { |
1428 | if ( visible ) { | 1428 | if ( visible ) { |
1429 | mViewManager->hide(); | 1429 | mViewManager->hide(); |
1430 | mDetails->show(); | 1430 | mDetails->show(); |
1431 | mIncSearchWidget->setFocus(); | 1431 | mIncSearchWidget->setFocus(); |
1432 | } | 1432 | } |
1433 | else { | 1433 | else { |
1434 | mViewManager->show(); | 1434 | mViewManager->show(); |
1435 | mDetails->hide(); | 1435 | mDetails->hide(); |
1436 | mViewManager->setFocusAV(); | 1436 | mViewManager->setFocusAV(); |
1437 | } | 1437 | } |
1438 | setJumpButtonBarVisible( !visible ); | 1438 | setJumpButtonBarVisible( !visible ); |
1439 | } | 1439 | } |
1440 | 1440 | ||
1441 | } | 1441 | } |
1442 | 1442 | ||
1443 | void KABCore::extensionChanged( int id ) | 1443 | void KABCore::extensionChanged( int id ) |
1444 | { | 1444 | { |
1445 | //change the details view only for non desktop systems | 1445 | //change the details view only for non desktop systems |
1446 | #ifndef DESKTOP_VERSION | 1446 | #ifndef DESKTOP_VERSION |
1447 | 1447 | ||
1448 | if (id == 0) | 1448 | if (id == 0) |
1449 | { | 1449 | { |
1450 | //the user disabled the extension. | 1450 | //the user disabled the extension. |
1451 | 1451 | ||
1452 | if (mMultipleViewsAtOnce) | 1452 | if (mMultipleViewsAtOnce) |
1453 | { // enable detailsview again | 1453 | { // enable detailsview again |
1454 | setDetailsVisible( true ); | 1454 | setDetailsVisible( true ); |
1455 | mActionDetails->setChecked( true ); | 1455 | mActionDetails->setChecked( true ); |
1456 | } | 1456 | } |
1457 | else | 1457 | else |
1458 | { //go back to the listview | 1458 | { //go back to the listview |
1459 | setDetailsVisible( false ); | 1459 | setDetailsVisible( false ); |
1460 | mActionDetails->setChecked( false ); | 1460 | mActionDetails->setChecked( false ); |
1461 | mActionDetails->setEnabled(true); | 1461 | mActionDetails->setEnabled(true); |
1462 | } | 1462 | } |
1463 | 1463 | ||
1464 | } | 1464 | } |
1465 | else | 1465 | else |
1466 | { | 1466 | { |
1467 | //the user enabled the extension. | 1467 | //the user enabled the extension. |
1468 | setDetailsVisible( false ); | 1468 | setDetailsVisible( false ); |
1469 | mActionDetails->setChecked( false ); | 1469 | mActionDetails->setChecked( false ); |
1470 | 1470 | ||
1471 | if (!mMultipleViewsAtOnce) | 1471 | if (!mMultipleViewsAtOnce) |
1472 | { | 1472 | { |
1473 | mActionDetails->setEnabled(false); | 1473 | mActionDetails->setEnabled(false); |
1474 | } | 1474 | } |
1475 | 1475 | ||
1476 | mExtensionManager->setSelectionChanged(); | 1476 | mExtensionManager->setSelectionChanged(); |
1477 | 1477 | ||
1478 | } | 1478 | } |
1479 | 1479 | ||
1480 | #endif// DESKTOP_VERSION | 1480 | #endif// DESKTOP_VERSION |
1481 | 1481 | ||
1482 | } | 1482 | } |
1483 | 1483 | ||
1484 | 1484 | ||
1485 | void KABCore::extensionModified( const KABC::Addressee::List &list ) | 1485 | void KABCore::extensionModified( const KABC::Addressee::List &list ) |
1486 | { | 1486 | { |
1487 | 1487 | ||
1488 | if ( list.count() != 0 ) { | 1488 | if ( list.count() != 0 ) { |
1489 | KABC::Addressee::List::ConstIterator it; | 1489 | KABC::Addressee::List::ConstIterator it; |
1490 | for ( it = list.begin(); it != list.end(); ++it ) | 1490 | for ( it = list.begin(); it != list.end(); ++it ) |
1491 | mAddressBook->insertAddressee( *it ); | 1491 | mAddressBook->insertAddressee( *it ); |
1492 | if ( list.count() > 1 ) | 1492 | if ( list.count() > 1 ) |
1493 | setModified(); | 1493 | setModified(); |
1494 | else | 1494 | else |
1495 | setModifiedWOrefresh(); | 1495 | setModifiedWOrefresh(); |
1496 | } | 1496 | } |
1497 | if ( list.count() == 0 ) | 1497 | if ( list.count() == 0 ) |
1498 | mViewManager->refreshView(); | 1498 | mViewManager->refreshView(); |
1499 | else | 1499 | else |
1500 | mViewManager->refreshView( list[ 0 ].uid() ); | 1500 | mViewManager->refreshView( list[ 0 ].uid() ); |
1501 | 1501 | ||
1502 | 1502 | ||
1503 | 1503 | ||
1504 | } | 1504 | } |
1505 | 1505 | ||
1506 | QString KABCore::getNameByPhone( const QString &phone ) | 1506 | QString KABCore::getNameByPhone( const QString &phone ) |
1507 | { | 1507 | { |
1508 | #ifndef KAB_EMBEDDED | 1508 | #ifndef KAB_EMBEDDED |
1509 | QRegExp r( "[/*/-/ ]" ); | 1509 | QRegExp r( "[/*/-/ ]" ); |
1510 | QString localPhone( phone ); | 1510 | QString localPhone( phone ); |
1511 | 1511 | ||
1512 | bool found = false; | 1512 | bool found = false; |
1513 | QString ownerName = ""; | 1513 | QString ownerName = ""; |
1514 | KABC::AddressBook::Iterator iter; | 1514 | KABC::AddressBook::Iterator iter; |
1515 | KABC::PhoneNumber::List::Iterator phoneIter; | 1515 | KABC::PhoneNumber::List::Iterator phoneIter; |
1516 | KABC::PhoneNumber::List phoneList; | 1516 | KABC::PhoneNumber::List phoneList; |
1517 | for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { | 1517 | for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { |
1518 | phoneList = (*iter).phoneNumbers(); | 1518 | phoneList = (*iter).phoneNumbers(); |
1519 | for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); | 1519 | for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); |
1520 | ++phoneIter) { | 1520 | ++phoneIter) { |
1521 | // Get rid of separator chars so just the numbers are compared. | 1521 | // Get rid of separator chars so just the numbers are compared. |
1522 | if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { | 1522 | if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { |
1523 | ownerName = (*iter).formattedName(); | 1523 | ownerName = (*iter).formattedName(); |
1524 | found = true; | 1524 | found = true; |
1525 | } | 1525 | } |
1526 | } | 1526 | } |
1527 | } | 1527 | } |
1528 | 1528 | ||
1529 | return ownerName; | 1529 | return ownerName; |
1530 | #else //KAB_EMBEDDED | 1530 | #else //KAB_EMBEDDED |
1531 | qDebug("KABCore::getNameByPhone finsih method"); | 1531 | qDebug("KABCore::getNameByPhone finsih method"); |
1532 | return ""; | 1532 | return ""; |
1533 | #endif //KAB_EMBEDDED | 1533 | #endif //KAB_EMBEDDED |
1534 | 1534 | ||
1535 | } | 1535 | } |
1536 | 1536 | ||
1537 | void KABCore::openConfigDialog() | 1537 | void KABCore::openConfigDialog() |
1538 | { | 1538 | { |
1539 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); | 1539 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); |
1540 | KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); | 1540 | KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); |
1541 | ConfigureDialog->addModule(kabcfg ); | 1541 | ConfigureDialog->addModule(kabcfg ); |
1542 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); | 1542 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); |
1543 | ConfigureDialog->addModule(kdelibcfg ); | 1543 | ConfigureDialog->addModule(kdelibcfg ); |
1544 | 1544 | ||
1545 | connect( ConfigureDialog, SIGNAL( applyClicked() ), | 1545 | connect( ConfigureDialog, SIGNAL( applyClicked() ), |
1546 | this, SLOT( configurationChanged() ) ); | 1546 | this, SLOT( configurationChanged() ) ); |
1547 | connect( ConfigureDialog, SIGNAL( okClicked() ), | 1547 | connect( ConfigureDialog, SIGNAL( okClicked() ), |
1548 | this, SLOT( configurationChanged() ) ); | 1548 | this, SLOT( configurationChanged() ) ); |
1549 | saveSettings(); | 1549 | saveSettings(); |
1550 | #ifndef DESKTOP_VERSION | 1550 | #ifndef DESKTOP_VERSION |
1551 | ConfigureDialog->showMaximized(); | 1551 | ConfigureDialog->showMaximized(); |
1552 | #endif | 1552 | #endif |
1553 | if ( ConfigureDialog->exec() ) | 1553 | if ( ConfigureDialog->exec() ) |
1554 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); | 1554 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); |
1555 | delete ConfigureDialog; | 1555 | delete ConfigureDialog; |
1556 | } | 1556 | } |
1557 | 1557 | ||
1558 | void KABCore::openLDAPDialog() | 1558 | void KABCore::openLDAPDialog() |
1559 | { | 1559 | { |
1560 | #ifndef KAB_EMBEDDED | 1560 | #ifndef KAB_EMBEDDED |
1561 | if ( !mLdapSearchDialog ) { | 1561 | if ( !mLdapSearchDialog ) { |
1562 | mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); | 1562 | mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); |
1563 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, | 1563 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, |
1564 | SLOT( refreshView() ) ); | 1564 | SLOT( refreshView() ) ); |
1565 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, | 1565 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, |
1566 | SLOT( setModified() ) ); | 1566 | SLOT( setModified() ) ); |
1567 | } else | 1567 | } else |
1568 | mLdapSearchDialog->restoreSettings(); | 1568 | mLdapSearchDialog->restoreSettings(); |
1569 | 1569 | ||
1570 | if ( mLdapSearchDialog->isOK() ) | 1570 | if ( mLdapSearchDialog->isOK() ) |
1571 | mLdapSearchDialog->exec(); | 1571 | mLdapSearchDialog->exec(); |
1572 | #else //KAB_EMBEDDED | 1572 | #else //KAB_EMBEDDED |
1573 | qDebug("KABCore::openLDAPDialog() finsih method"); | 1573 | qDebug("KABCore::openLDAPDialog() finsih method"); |
1574 | #endif //KAB_EMBEDDED | 1574 | #endif //KAB_EMBEDDED |
1575 | } | 1575 | } |
1576 | 1576 | ||
1577 | void KABCore::print() | 1577 | void KABCore::print() |
1578 | { | 1578 | { |
1579 | #ifndef KAB_EMBEDDED | 1579 | #ifndef KAB_EMBEDDED |
1580 | KPrinter printer; | 1580 | KPrinter printer; |
1581 | if ( !printer.setup( this ) ) | 1581 | if ( !printer.setup( this ) ) |
1582 | return; | 1582 | return; |
1583 | 1583 | ||
1584 | KABPrinting::PrintingWizard wizard( &printer, mAddressBook, | 1584 | KABPrinting::PrintingWizard wizard( &printer, mAddressBook, |
1585 | mViewManager->selectedUids(), this ); | 1585 | mViewManager->selectedUids(), this ); |
1586 | 1586 | ||
1587 | wizard.exec(); | 1587 | wizard.exec(); |
1588 | #else //KAB_EMBEDDED | 1588 | #else //KAB_EMBEDDED |
1589 | qDebug("KABCore::print() finsih method"); | 1589 | qDebug("KABCore::print() finsih method"); |
1590 | #endif //KAB_EMBEDDED | 1590 | #endif //KAB_EMBEDDED |
1591 | 1591 | ||
1592 | } | 1592 | } |
1593 | 1593 | ||
1594 | 1594 | ||
1595 | void KABCore::addGUIClient( KXMLGUIClient *client ) | 1595 | void KABCore::addGUIClient( KXMLGUIClient *client ) |
1596 | { | 1596 | { |
1597 | if ( mGUIClient ) | 1597 | if ( mGUIClient ) |
1598 | mGUIClient->insertChildClient( client ); | 1598 | mGUIClient->insertChildClient( client ); |
1599 | else | 1599 | else |
1600 | KMessageBox::error( this, "no KXMLGUICLient"); | 1600 | KMessageBox::error( this, "no KXMLGUICLient"); |
1601 | } | 1601 | } |
1602 | 1602 | ||
1603 | 1603 | ||
1604 | void KABCore::configurationChanged() | 1604 | void KABCore::configurationChanged() |
1605 | { | 1605 | { |
1606 | mExtensionManager->reconfigure(); | 1606 | mExtensionManager->reconfigure(); |
1607 | } | 1607 | } |
1608 | 1608 | ||
1609 | void KABCore::addressBookChanged() | 1609 | void KABCore::addressBookChanged() |
1610 | { | 1610 | { |
1611 | /*US | 1611 | /*US |
1612 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); | 1612 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); |
1613 | while ( it.current() ) { | 1613 | while ( it.current() ) { |
1614 | if ( it.current()->dirty() ) { | 1614 | if ( it.current()->dirty() ) { |
1615 | QString text = i18n( "Data has been changed externally. Unsaved " | 1615 | QString text = i18n( "Data has been changed externally. Unsaved " |
1616 | "changes will be lost." ); | 1616 | "changes will be lost." ); |
1617 | KMessageBox::information( this, text ); | 1617 | KMessageBox::information( this, text ); |
1618 | } | 1618 | } |
1619 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); | 1619 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); |
1620 | ++it; | 1620 | ++it; |
1621 | } | 1621 | } |
1622 | */ | 1622 | */ |
1623 | if (mEditorDialog) | 1623 | if (mEditorDialog) |
1624 | { | 1624 | { |
1625 | if (mEditorDialog->dirty()) | 1625 | if (mEditorDialog->dirty()) |
1626 | { | 1626 | { |
1627 | QString text = i18n( "Data has been changed externally. Unsaved " | 1627 | QString text = i18n( "Data has been changed externally. Unsaved " |
1628 | "changes will be lost." ); | 1628 | "changes will be lost." ); |
1629 | KMessageBox::information( this, text ); | 1629 | KMessageBox::information( this, text ); |
1630 | } | 1630 | } |
1631 | QString currentuid = mEditorDialog->addressee().uid(); | 1631 | QString currentuid = mEditorDialog->addressee().uid(); |
1632 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); | 1632 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); |
1633 | } | 1633 | } |
1634 | mViewManager->refreshView(); | 1634 | mViewManager->refreshView(); |
1635 | // mDetails->refreshView(); | 1635 | // mDetails->refreshView(); |
1636 | 1636 | ||
1637 | 1637 | ||
1638 | } | 1638 | } |
1639 | 1639 | ||
1640 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, | 1640 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, |
1641 | const char *name ) | 1641 | const char *name ) |
1642 | { | 1642 | { |
1643 | 1643 | ||
1644 | if ( mEditorDialog == 0 ) { | 1644 | if ( mEditorDialog == 0 ) { |
1645 | mEditorDialog = new AddresseeEditorDialog( this, parent, | 1645 | mEditorDialog = new AddresseeEditorDialog( this, parent, |
1646 | name ? name : "editorDialog" ); | 1646 | name ? name : "editorDialog" ); |
1647 | 1647 | ||
1648 | 1648 | ||
1649 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), | 1649 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), |
1650 | SLOT( contactModified( const KABC::Addressee& ) ) ); | 1650 | SLOT( contactModified( const KABC::Addressee& ) ) ); |
1651 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), | 1651 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), |
1652 | // SLOT( slotEditorDestroyed( const QString& ) ) ; | 1652 | // SLOT( slotEditorDestroyed( const QString& ) ) ; |
1653 | } | 1653 | } |
1654 | 1654 | ||
1655 | return mEditorDialog; | 1655 | return mEditorDialog; |
1656 | } | 1656 | } |
1657 | 1657 | ||
1658 | void KABCore::slotEditorDestroyed( const QString &uid ) | 1658 | void KABCore::slotEditorDestroyed( const QString &uid ) |
1659 | { | 1659 | { |
1660 | //mEditorDict.remove( uid ); | 1660 | //mEditorDict.remove( uid ); |
1661 | } | 1661 | } |
1662 | 1662 | ||
1663 | void KABCore::initGUI() | 1663 | void KABCore::initGUI() |
1664 | { | 1664 | { |
1665 | #ifndef KAB_EMBEDDED | 1665 | #ifndef KAB_EMBEDDED |
1666 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1666 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1667 | topLayout->setSpacing( KDialogBase::spacingHint() ); | 1667 | topLayout->setSpacing( KDialogBase::spacingHint() ); |
1668 | 1668 | ||
1669 | mExtensionBarSplitter = new QSplitter( this ); | 1669 | mExtensionBarSplitter = new QSplitter( this ); |
1670 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); | 1670 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); |
1671 | 1671 | ||
1672 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); | 1672 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); |
1673 | 1673 | ||
1674 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1674 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1675 | mIncSearchWidget = new IncSearchWidget( viewSpace ); | 1675 | mIncSearchWidget = new IncSearchWidget( viewSpace ); |
1676 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1676 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1677 | SLOT( incrementalSearch( const QString& ) ) ); | 1677 | SLOT( incrementalSearch( const QString& ) ) ); |
1678 | 1678 | ||
1679 | mViewManager = new ViewManager( this, viewSpace ); | 1679 | mViewManager = new ViewManager( this, viewSpace ); |
1680 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1680 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1681 | 1681 | ||
1682 | mDetails = new ViewContainer( mDetailsSplitter ); | 1682 | mDetails = new ViewContainer( mDetailsSplitter ); |
1683 | 1683 | ||
1684 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1684 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1685 | 1685 | ||
1686 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1686 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1687 | 1687 | ||
1688 | topLayout->addWidget( mExtensionBarSplitter ); | 1688 | topLayout->addWidget( mExtensionBarSplitter ); |
1689 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); | 1689 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); |
1690 | topLayout->addWidget( mJumpButtonBar ); | 1690 | topLayout->addWidget( mJumpButtonBar ); |
1691 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); | 1691 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); |
1692 | 1692 | ||
1693 | mXXPortManager = new XXPortManager( this, this ); | 1693 | mXXPortManager = new XXPortManager( this, this ); |
1694 | 1694 | ||
1695 | #else //KAB_EMBEDDED | 1695 | #else //KAB_EMBEDDED |
1696 | //US initialize viewMenu before settingup viewmanager. | 1696 | //US initialize viewMenu before settingup viewmanager. |
1697 | // Viewmanager needs this menu to plugin submenues. | 1697 | // Viewmanager needs this menu to plugin submenues. |
1698 | viewMenu = new QPopupMenu( this ); | 1698 | viewMenu = new QPopupMenu( this ); |
1699 | settingsMenu = new QPopupMenu( this ); | 1699 | settingsMenu = new QPopupMenu( this ); |
1700 | //filterMenu = new QPopupMenu( this ); | 1700 | //filterMenu = new QPopupMenu( this ); |
1701 | ImportMenu = new QPopupMenu( this ); | 1701 | ImportMenu = new QPopupMenu( this ); |
1702 | ExportMenu = new QPopupMenu( this ); | 1702 | ExportMenu = new QPopupMenu( this ); |
1703 | syncMenu = new QPopupMenu( this ); | 1703 | syncMenu = new QPopupMenu( this ); |
1704 | changeMenu= new QPopupMenu( this ); | 1704 | changeMenu= new QPopupMenu( this ); |
1705 | beamMenu= new QPopupMenu( this ); | 1705 | beamMenu= new QPopupMenu( this ); |
1706 | 1706 | ||
1707 | //US since we have no splitter for the embedded system, setup | 1707 | //US since we have no splitter for the embedded system, setup |
1708 | // a layout with two frames. One left and one right. | 1708 | // a layout with two frames. One left and one right. |
1709 | 1709 | ||
1710 | QBoxLayout *topLayout; | 1710 | QBoxLayout *topLayout; |
1711 | 1711 | ||
1712 | // = new QHBoxLayout( this ); | 1712 | // = new QHBoxLayout( this ); |
1713 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); | 1713 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); |
1714 | 1714 | ||
1715 | // QWidget *mainBox = new QWidget( this ); | 1715 | // QWidget *mainBox = new QWidget( this ); |
1716 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); | 1716 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); |
1717 | 1717 | ||
1718 | #ifdef DESKTOP_VERSION | 1718 | #ifdef DESKTOP_VERSION |
1719 | topLayout = new QHBoxLayout( this ); | 1719 | topLayout = new QHBoxLayout( this ); |
1720 | 1720 | ||
1721 | 1721 | ||
1722 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1722 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1723 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1723 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1724 | 1724 | ||
1725 | topLayout->addWidget(mMiniSplitter ); | 1725 | topLayout->addWidget(mMiniSplitter ); |
1726 | 1726 | ||
1727 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); | 1727 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); |
1728 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1728 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1729 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); | 1729 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); |
1730 | mDetails = new ViewContainer( mMiniSplitter ); | 1730 | mDetails = new ViewContainer( mMiniSplitter ); |
1731 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1731 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1732 | #else | 1732 | #else |
1733 | if ( QApplication::desktop()->width() > 480 ) { | 1733 | if ( QApplication::desktop()->width() > 480 ) { |
1734 | topLayout = new QHBoxLayout( this ); | 1734 | topLayout = new QHBoxLayout( this ); |
1735 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1735 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1736 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1736 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1737 | } else { | 1737 | } else { |
1738 | 1738 | ||
1739 | topLayout = new QHBoxLayout( this ); | 1739 | topLayout = new QHBoxLayout( this ); |
1740 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); | 1740 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); |
1741 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1741 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1742 | } | 1742 | } |
1743 | 1743 | ||
1744 | topLayout->addWidget(mMiniSplitter ); | 1744 | topLayout->addWidget(mMiniSplitter ); |
1745 | mViewManager = new ViewManager( this, mMiniSplitter ); | 1745 | mViewManager = new ViewManager( this, mMiniSplitter ); |
1746 | mDetails = new ViewContainer( mMiniSplitter ); | 1746 | mDetails = new ViewContainer( mMiniSplitter ); |
1747 | 1747 | ||
1748 | 1748 | ||
1749 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); | 1749 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); |
1750 | #endif | 1750 | #endif |
1751 | //eh->hide(); | 1751 | //eh->hide(); |
1752 | // topLayout->addWidget(mExtensionManager ); | 1752 | // topLayout->addWidget(mExtensionManager ); |
1753 | 1753 | ||
1754 | 1754 | ||
1755 | /*US | 1755 | /*US |
1756 | #ifndef KAB_NOSPLITTER | 1756 | #ifndef KAB_NOSPLITTER |
1757 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1757 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1758 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1758 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1759 | topLayout->setSpacing( 10 ); | 1759 | topLayout->setSpacing( 10 ); |
1760 | 1760 | ||
1761 | mDetailsSplitter = new QSplitter( this ); | 1761 | mDetailsSplitter = new QSplitter( this ); |
1762 | 1762 | ||
1763 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1763 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1764 | 1764 | ||
1765 | mViewManager = new ViewManager( this, viewSpace ); | 1765 | mViewManager = new ViewManager( this, viewSpace ); |
1766 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1766 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1767 | 1767 | ||
1768 | mDetails = new ViewContainer( mDetailsSplitter ); | 1768 | mDetails = new ViewContainer( mDetailsSplitter ); |
1769 | 1769 | ||
1770 | topLayout->addWidget( mDetailsSplitter ); | 1770 | topLayout->addWidget( mDetailsSplitter ); |
1771 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1771 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1772 | #else //KAB_NOSPLITTER | 1772 | #else //KAB_NOSPLITTER |
1773 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1773 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1774 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1774 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1775 | topLayout->setSpacing( 10 ); | 1775 | topLayout->setSpacing( 10 ); |
1776 | 1776 | ||
1777 | // mDetailsSplitter = new QSplitter( this ); | 1777 | // mDetailsSplitter = new QSplitter( this ); |
1778 | 1778 | ||
1779 | QVBox *viewSpace = new QVBox( this ); | 1779 | QVBox *viewSpace = new QVBox( this ); |
1780 | 1780 | ||
1781 | mViewManager = new ViewManager( this, viewSpace ); | 1781 | mViewManager = new ViewManager( this, viewSpace ); |
1782 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1782 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1783 | 1783 | ||
1784 | mDetails = new ViewContainer( this ); | 1784 | mDetails = new ViewContainer( this ); |
1785 | 1785 | ||
1786 | topLayout->addWidget( viewSpace ); | 1786 | topLayout->addWidget( viewSpace ); |
1787 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1787 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1788 | topLayout->addWidget( mDetails ); | 1788 | topLayout->addWidget( mDetails ); |
1789 | #endif //KAB_NOSPLITTER | 1789 | #endif //KAB_NOSPLITTER |
1790 | */ | 1790 | */ |
1791 | 1791 | ||
1792 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); | 1792 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); |
1793 | syncManager->setBlockSave(false); | 1793 | syncManager->setBlockSave(false); |
1794 | 1794 | ||
1795 | connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); | 1795 | connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); |
1796 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); | 1796 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); |
1797 | syncManager->setDefaultFileName( sentSyncFile()); | 1797 | QString sync_file = sentSyncFile(); |
1798 | qDebug("KABCore::initGUI()::setting tmp sync file to:%s ",sync_file.latin1()); | ||
1799 | syncManager->setDefaultFileName( sync_file ); | ||
1798 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); | 1800 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); |
1799 | 1801 | ||
1800 | #endif //KAB_EMBEDDED | 1802 | #endif //KAB_EMBEDDED |
1801 | initActions(); | 1803 | initActions(); |
1802 | 1804 | ||
1803 | #ifdef KAB_EMBEDDED | 1805 | #ifdef KAB_EMBEDDED |
1804 | addActionsManually(); | 1806 | addActionsManually(); |
1805 | //US make sure the export and import menues are initialized before creating the xxPortManager. | 1807 | //US make sure the export and import menues are initialized before creating the xxPortManager. |
1806 | mXXPortManager = new XXPortManager( this, this ); | 1808 | mXXPortManager = new XXPortManager( this, this ); |
1807 | 1809 | ||
1808 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); | 1810 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); |
1809 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); | 1811 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); |
1810 | // mActionQuit->plug ( mMainWindow->toolBar()); | 1812 | // mActionQuit->plug ( mMainWindow->toolBar()); |
1811 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); | 1813 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); |
1812 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); | 1814 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); |
1813 | // mIncSearchWidget->hide(); | 1815 | // mIncSearchWidget->hide(); |
1814 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1816 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1815 | SLOT( incrementalSearch( const QString& ) ) ); | 1817 | SLOT( incrementalSearch( const QString& ) ) ); |
1816 | connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); | 1818 | connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); |
1817 | connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); | 1819 | connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); |
1818 | 1820 | ||
1819 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1821 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1820 | 1822 | ||
1821 | topLayout->addWidget( mJumpButtonBar ); | 1823 | topLayout->addWidget( mJumpButtonBar ); |
1822 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); | 1824 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); |
1823 | 1825 | ||
1824 | // mMainWindow->getIconToolBar()->raise(); | 1826 | // mMainWindow->getIconToolBar()->raise(); |
1825 | 1827 | ||
1826 | #endif //KAB_EMBEDDED | 1828 | #endif //KAB_EMBEDDED |
1827 | 1829 | ||
1828 | } | 1830 | } |
1829 | void KABCore::initActions() | 1831 | void KABCore::initActions() |
1830 | { | 1832 | { |
1831 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 1833 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
1832 | 1834 | ||
1833 | #ifndef KAB_EMBEDDED | 1835 | #ifndef KAB_EMBEDDED |
1834 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), | 1836 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), |
1835 | SLOT( clipboardDataChanged() ) ); | 1837 | SLOT( clipboardDataChanged() ) ); |
1836 | #endif //KAB_EMBEDDED | 1838 | #endif //KAB_EMBEDDED |
1837 | 1839 | ||
1838 | // file menu | 1840 | // file menu |
1839 | if ( mIsPart ) { | 1841 | if ( mIsPart ) { |
1840 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, | 1842 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, |
1841 | SLOT( sendMail() ), actionCollection(), | 1843 | SLOT( sendMail() ), actionCollection(), |
1842 | "kaddressbook_mail" ); | 1844 | "kaddressbook_mail" ); |
1843 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, | 1845 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, |
1844 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); | 1846 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); |
1845 | 1847 | ||
1846 | } else { | 1848 | } else { |
1847 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); | 1849 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); |
1848 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); | 1850 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); |
1849 | } | 1851 | } |
1850 | 1852 | ||
1851 | 1853 | ||
1852 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, | 1854 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, |
1853 | SLOT( save() ), actionCollection(), "file_sync" ); | 1855 | SLOT( save() ), actionCollection(), "file_sync" ); |
1854 | 1856 | ||
1855 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, | 1857 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, |
1856 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); | 1858 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); |
1857 | 1859 | ||
1858 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, | 1860 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, |
1859 | this, SLOT( mailVCard() ), | 1861 | this, SLOT( mailVCard() ), |
1860 | actionCollection(), "file_mail_vcard"); | 1862 | actionCollection(), "file_mail_vcard"); |
1861 | 1863 | ||
1862 | mActionExport2phone = new KAction( i18n( "Export to phone" ), "ex2phone", 0, this, | 1864 | mActionExport2phone = new KAction( i18n( "Export to phone" ), "ex2phone", 0, this, |
1863 | SLOT( export2phone() ), actionCollection(), | 1865 | SLOT( export2phone() ), actionCollection(), |
1864 | "kaddressbook_ex2phone" ); | 1866 | "kaddressbook_ex2phone" ); |
1865 | 1867 | ||
1866 | mActionBeamVCard = 0; | 1868 | mActionBeamVCard = 0; |
1867 | mActionBeam = 0; | 1869 | mActionBeam = 0; |
1868 | 1870 | ||
1869 | #ifndef DESKTOP_VERSION | 1871 | #ifndef DESKTOP_VERSION |
1870 | if ( Ir::supported() ) { | 1872 | if ( Ir::supported() ) { |
1871 | mActionBeamVCard = new KAction( i18n( "Beam v&Card(s)..." ), "beam", 0, this, | 1873 | mActionBeamVCard = new KAction( i18n( "Beam v&Card(s)..." ), "beam", 0, this, |
1872 | SLOT( beamVCard() ), actionCollection(), | 1874 | SLOT( beamVCard() ), actionCollection(), |
1873 | "kaddressbook_beam_vcard" ); | 1875 | "kaddressbook_beam_vcard" ); |
1874 | 1876 | ||
1875 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, | 1877 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, |
1876 | SLOT( beamMySelf() ), actionCollection(), | 1878 | SLOT( beamMySelf() ), actionCollection(), |
1877 | "kaddressbook_beam_myself" ); | 1879 | "kaddressbook_beam_myself" ); |
1878 | } | 1880 | } |
1879 | #endif | 1881 | #endif |
1880 | 1882 | ||
1881 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, | 1883 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, |
1882 | this, SLOT( editContact2() ), | 1884 | this, SLOT( editContact2() ), |
1883 | actionCollection(), "file_properties" ); | 1885 | actionCollection(), "file_properties" ); |
1884 | 1886 | ||
1885 | #ifdef KAB_EMBEDDED | 1887 | #ifdef KAB_EMBEDDED |
1886 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); | 1888 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); |
1887 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, | 1889 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, |
1888 | mMainWindow, SLOT( exit() ), | 1890 | mMainWindow, SLOT( exit() ), |
1889 | actionCollection(), "quit" ); | 1891 | actionCollection(), "quit" ); |
1890 | #endif //KAB_EMBEDDED | 1892 | #endif //KAB_EMBEDDED |
1891 | 1893 | ||
1892 | // edit menu | 1894 | // edit menu |
1893 | if ( mIsPart ) { | 1895 | if ( mIsPart ) { |
1894 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, | 1896 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, |
1895 | SLOT( copyContacts() ), actionCollection(), | 1897 | SLOT( copyContacts() ), actionCollection(), |
1896 | "kaddressbook_copy" ); | 1898 | "kaddressbook_copy" ); |
1897 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, | 1899 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, |
1898 | SLOT( cutContacts() ), actionCollection(), | 1900 | SLOT( cutContacts() ), actionCollection(), |
1899 | "kaddressbook_cut" ); | 1901 | "kaddressbook_cut" ); |
1900 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, | 1902 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, |
1901 | SLOT( pasteContacts() ), actionCollection(), | 1903 | SLOT( pasteContacts() ), actionCollection(), |
1902 | "kaddressbook_paste" ); | 1904 | "kaddressbook_paste" ); |
1903 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, | 1905 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, |
1904 | SLOT( selectAllContacts() ), actionCollection(), | 1906 | SLOT( selectAllContacts() ), actionCollection(), |
1905 | "kaddressbook_select_all" ); | 1907 | "kaddressbook_select_all" ); |
1906 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, | 1908 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, |
1907 | SLOT( undo() ), actionCollection(), | 1909 | SLOT( undo() ), actionCollection(), |
1908 | "kaddressbook_undo" ); | 1910 | "kaddressbook_undo" ); |
1909 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, | 1911 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, |
1910 | this, SLOT( redo() ), actionCollection(), | 1912 | this, SLOT( redo() ), actionCollection(), |
1911 | "kaddressbook_redo" ); | 1913 | "kaddressbook_redo" ); |
1912 | } else { | 1914 | } else { |
1913 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); | 1915 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); |
1914 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); | 1916 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); |
1915 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); | 1917 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); |
1916 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); | 1918 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); |
1917 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); | 1919 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); |
1918 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); | 1920 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); |
1919 | } | 1921 | } |
1920 | 1922 | ||
1921 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", | 1923 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", |
1922 | Key_Delete, this, SLOT( deleteContacts() ), | 1924 | Key_Delete, this, SLOT( deleteContacts() ), |
1923 | actionCollection(), "edit_delete" ); | 1925 | actionCollection(), "edit_delete" ); |
1924 | 1926 | ||
1925 | mActionUndo->setEnabled( false ); | 1927 | mActionUndo->setEnabled( false ); |
1926 | mActionRedo->setEnabled( false ); | 1928 | mActionRedo->setEnabled( false ); |
1927 | 1929 | ||
1928 | // settings menu | 1930 | // settings menu |
1929 | #ifdef KAB_EMBEDDED | 1931 | #ifdef KAB_EMBEDDED |
1930 | //US special menuentry to configure the addressbook resources. On KDE | 1932 | //US special menuentry to configure the addressbook resources. On KDE |
1931 | // you do that through the control center !!! | 1933 | // you do that through the control center !!! |
1932 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, | 1934 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, |
1933 | SLOT( configureResources() ), actionCollection(), | 1935 | SLOT( configureResources() ), actionCollection(), |
1934 | "kaddressbook_configure_resources" ); | 1936 | "kaddressbook_configure_resources" ); |
1935 | #endif //KAB_EMBEDDED | 1937 | #endif //KAB_EMBEDDED |
1936 | 1938 | ||
1937 | if ( mIsPart ) { | 1939 | if ( mIsPart ) { |
1938 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, | 1940 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, |
1939 | SLOT( openConfigDialog() ), actionCollection(), | 1941 | SLOT( openConfigDialog() ), actionCollection(), |
1940 | "kaddressbook_configure" ); | 1942 | "kaddressbook_configure" ); |
1941 | 1943 | ||
1942 | //US not implemented yet | 1944 | //US not implemented yet |
1943 | //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, | 1945 | //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, |
1944 | // this, SLOT( configureKeyBindings() ), actionCollection(), | 1946 | // this, SLOT( configureKeyBindings() ), actionCollection(), |
1945 | // "kaddressbook_configure_shortcuts" ); | 1947 | // "kaddressbook_configure_shortcuts" ); |
1946 | #ifdef KAB_EMBEDDED | 1948 | #ifdef KAB_EMBEDDED |
1947 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); | 1949 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); |
1948 | mActionConfigureToolbars->setEnabled( false ); | 1950 | mActionConfigureToolbars->setEnabled( false ); |
1949 | #endif //KAB_EMBEDDED | 1951 | #endif //KAB_EMBEDDED |
1950 | 1952 | ||
1951 | } else { | 1953 | } else { |
1952 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); | 1954 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); |
1953 | 1955 | ||
1954 | //US not implemented yet | 1956 | //US not implemented yet |
1955 | //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); | 1957 | //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); |
1956 | } | 1958 | } |
1957 | 1959 | ||
1958 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, | 1960 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, |
1959 | actionCollection(), "options_show_jump_bar" ); | 1961 | actionCollection(), "options_show_jump_bar" ); |
1960 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); | 1962 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); |
1961 | 1963 | ||
1962 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, | 1964 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, |
1963 | actionCollection(), "options_show_details" ); | 1965 | actionCollection(), "options_show_details" ); |
1964 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); | 1966 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); |
1965 | 1967 | ||
1966 | 1968 | ||
1967 | mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, | 1969 | mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, |
1968 | SLOT( toggleBeamReceive() ), actionCollection(), | 1970 | SLOT( toggleBeamReceive() ), actionCollection(), |
1969 | "kaddressbook_beam_rec" ); | 1971 | "kaddressbook_beam_rec" ); |
1970 | 1972 | ||
1971 | 1973 | ||
1972 | // misc | 1974 | // misc |
1973 | // only enable LDAP lookup if we can handle the protocol | 1975 | // only enable LDAP lookup if we can handle the protocol |
1974 | #ifndef KAB_EMBEDDED | 1976 | #ifndef KAB_EMBEDDED |
1975 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { | 1977 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { |
1976 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, | 1978 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, |
1977 | this, SLOT( openLDAPDialog() ), actionCollection(), | 1979 | this, SLOT( openLDAPDialog() ), actionCollection(), |
1978 | "ldap_lookup" ); | 1980 | "ldap_lookup" ); |
1979 | } | 1981 | } |
1980 | #else //KAB_EMBEDDED | 1982 | #else //KAB_EMBEDDED |
1981 | //qDebug("KABCore::initActions() LDAP has to be implemented"); | 1983 | //qDebug("KABCore::initActions() LDAP has to be implemented"); |
1982 | #endif //KAB_EMBEDDED | 1984 | #endif //KAB_EMBEDDED |
1983 | 1985 | ||
1984 | 1986 | ||
1985 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, | 1987 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, |
1986 | SLOT( setWhoAmI() ), actionCollection(), | 1988 | SLOT( setWhoAmI() ), actionCollection(), |
1987 | "set_personal" ); | 1989 | "set_personal" ); |
1988 | 1990 | ||
1989 | 1991 | ||
1990 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, | 1992 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, |
1991 | SLOT( setCategories() ), actionCollection(), | 1993 | SLOT( setCategories() ), actionCollection(), |
1992 | "edit_set_categories" ); | 1994 | "edit_set_categories" ); |
1993 | mActionEditCategories = new KAction( i18n( "Edit Categories" ), 0, this, | 1995 | mActionEditCategories = new KAction( i18n( "Edit Categories" ), 0, this, |
1994 | SLOT( editCategories() ), actionCollection(), | 1996 | SLOT( editCategories() ), actionCollection(), |
1995 | "edit__categories" ); | 1997 | "edit__categories" ); |
1996 | 1998 | ||
1997 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, | 1999 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, |
1998 | SLOT( removeVoice() ), actionCollection(), | 2000 | SLOT( removeVoice() ), actionCollection(), |
1999 | "remove_voice" ); | 2001 | "remove_voice" ); |
2000 | 2002 | ||
2001 | mActionManageCategories= new KAction( i18n( "Manage new categories..." ), 0, this, | 2003 | mActionManageCategories= new KAction( i18n( "Manage new categories..." ), 0, this, |
2002 | SLOT( manageCategories() ), actionCollection(), | 2004 | SLOT( manageCategories() ), actionCollection(), |
2003 | "remove_voice" ); | 2005 | "remove_voice" ); |
2004 | 2006 | ||
2005 | 2007 | ||
2006 | mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, | 2008 | mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, |
2007 | SLOT( importFromOL() ), actionCollection(), | 2009 | SLOT( importFromOL() ), actionCollection(), |
2008 | "import_OL" ); | 2010 | "import_OL" ); |
2009 | #ifdef KAB_EMBEDDED | 2011 | #ifdef KAB_EMBEDDED |
2010 | mActionLicence = new KAction( i18n( "Licence" ), 0, | 2012 | mActionLicence = new KAction( i18n( "Licence" ), 0, |
2011 | this, SLOT( showLicence() ), actionCollection(), | 2013 | this, SLOT( showLicence() ), actionCollection(), |
2012 | "licence_about_data" ); | 2014 | "licence_about_data" ); |
2013 | mActionFaq = new KAction( i18n( "Faq" ), 0, | 2015 | mActionFaq = new KAction( i18n( "Faq" ), 0, |
2014 | this, SLOT( faq() ), actionCollection(), | 2016 | this, SLOT( faq() ), actionCollection(), |
2015 | "faq_about_data" ); | 2017 | "faq_about_data" ); |
2016 | mActionWN = new KAction( i18n( "What's New?" ), 0, | 2018 | mActionWN = new KAction( i18n( "What's New?" ), 0, |
2017 | this, SLOT( whatsnew() ), actionCollection(), | 2019 | this, SLOT( whatsnew() ), actionCollection(), |
2018 | "wn" ); | 2020 | "wn" ); |
2019 | mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, | 2021 | mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, |
2020 | this, SLOT( synchowto() ), actionCollection(), | 2022 | this, SLOT( synchowto() ), actionCollection(), |
2021 | "sync" ); | 2023 | "sync" ); |
2022 | mActionKdeSyncHowto = new KAction( i18n( "Kde Sync HowTo" ), 0, | 2024 | mActionKdeSyncHowto = new KAction( i18n( "Kde Sync HowTo" ), 0, |
2023 | this, SLOT( kdesynchowto() ), actionCollection(), | 2025 | this, SLOT( kdesynchowto() ), actionCollection(), |
2024 | "kdesync" ); | 2026 | "kdesync" ); |
2025 | mActionMultiSyncHowto = new KAction( i18n( "Multi Sync HowTo" ), 0, | 2027 | mActionMultiSyncHowto = new KAction( i18n( "Multi Sync HowTo" ), 0, |
2026 | this, SLOT( multisynchowto() ), actionCollection(), | 2028 | this, SLOT( multisynchowto() ), actionCollection(), |
2027 | "multisync" ); | 2029 | "multisync" ); |
2028 | 2030 | ||
2029 | mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, | 2031 | mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, |
2030 | this, SLOT( createAboutData() ), actionCollection(), | 2032 | this, SLOT( createAboutData() ), actionCollection(), |
2031 | "kaddressbook_about_data" ); | 2033 | "kaddressbook_about_data" ); |
2032 | #endif //KAB_EMBEDDED | 2034 | #endif //KAB_EMBEDDED |
2033 | 2035 | ||
2034 | clipboardDataChanged(); | 2036 | clipboardDataChanged(); |
2035 | connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); | 2037 | connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); |
2036 | connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); | 2038 | connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); |
2037 | } | 2039 | } |
2038 | 2040 | ||
2039 | //US we need this function, to plug all actions into the correct menues. | 2041 | //US we need this function, to plug all actions into the correct menues. |
2040 | // KDE uses a XML format to plug the actions, but we work her without this overhead. | 2042 | // KDE uses a XML format to plug the actions, but we work her without this overhead. |
2041 | void KABCore::addActionsManually() | 2043 | void KABCore::addActionsManually() |
2042 | { | 2044 | { |
2043 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 2045 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
2044 | 2046 | ||
2045 | #ifdef KAB_EMBEDDED | 2047 | #ifdef KAB_EMBEDDED |
2046 | QPopupMenu *fileMenu = new QPopupMenu( this ); | 2048 | QPopupMenu *fileMenu = new QPopupMenu( this ); |
2047 | QPopupMenu *editMenu = new QPopupMenu( this ); | 2049 | QPopupMenu *editMenu = new QPopupMenu( this ); |
2048 | QPopupMenu *helpMenu = new QPopupMenu( this ); | 2050 | QPopupMenu *helpMenu = new QPopupMenu( this ); |
2049 | 2051 | ||
2050 | KToolBar* tb = mMainWindow->toolBar(); | 2052 | KToolBar* tb = mMainWindow->toolBar(); |
2051 | 2053 | ||
2052 | #ifndef DESKTOP_VERSION | 2054 | #ifndef DESKTOP_VERSION |
2053 | if ( KABPrefs::instance()->mFullMenuBarVisible ) { | 2055 | if ( KABPrefs::instance()->mFullMenuBarVisible ) { |
2054 | #endif | 2056 | #endif |
2055 | QMenuBar* mb = mMainWindow->menuBar(); | 2057 | QMenuBar* mb = mMainWindow->menuBar(); |
2056 | 2058 | ||
2057 | //US setup menubar. | 2059 | //US setup menubar. |
2058 | //Disable the following block if you do not want to have a menubar. | 2060 | //Disable the following block if you do not want to have a menubar. |
2059 | mb->insertItem( i18n("&File"), fileMenu ); | 2061 | mb->insertItem( i18n("&File"), fileMenu ); |
2060 | mb->insertItem( i18n("&Edit"), editMenu ); | 2062 | mb->insertItem( i18n("&Edit"), editMenu ); |
2061 | mb->insertItem( i18n("&View"), viewMenu ); | 2063 | mb->insertItem( i18n("&View"), viewMenu ); |
2062 | mb->insertItem( i18n("&Settings"), settingsMenu ); | 2064 | mb->insertItem( i18n("&Settings"), settingsMenu ); |
2063 | mb->insertItem( i18n("Synchronize"), syncMenu ); | 2065 | mb->insertItem( i18n("Synchronize"), syncMenu ); |
2064 | //mb->insertItem( i18n("&Change"), changeMenu ); | 2066 | //mb->insertItem( i18n("&Change"), changeMenu ); |
2065 | mb->insertItem( i18n("&Help"), helpMenu ); | 2067 | mb->insertItem( i18n("&Help"), helpMenu ); |
2066 | mIncSearchWidget = new IncSearchWidget( tb ); | 2068 | mIncSearchWidget = new IncSearchWidget( tb ); |
2067 | // tb->insertWidget(-1, 0, mIncSearchWidget); | 2069 | // tb->insertWidget(-1, 0, mIncSearchWidget); |
2068 | #ifndef DESKTOP_VERSION | 2070 | #ifndef DESKTOP_VERSION |
2069 | } else { | 2071 | } else { |
2070 | //US setup toolbar | 2072 | //US setup toolbar |
2071 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); | 2073 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); |
2072 | QPopupMenu *popupBarTB = new QPopupMenu( this ); | 2074 | QPopupMenu *popupBarTB = new QPopupMenu( this ); |
2073 | menuBarTB->insertItem( "ME", popupBarTB); | 2075 | menuBarTB->insertItem( "ME", popupBarTB); |
2074 | tb->insertWidget(-1, 0, menuBarTB); | 2076 | tb->insertWidget(-1, 0, menuBarTB); |
2075 | mIncSearchWidget = new IncSearchWidget( tb ); | 2077 | mIncSearchWidget = new IncSearchWidget( tb ); |
2076 | 2078 | ||
2077 | tb->enableMoving(false); | 2079 | tb->enableMoving(false); |
2078 | popupBarTB->insertItem( i18n("&File"), fileMenu ); | 2080 | popupBarTB->insertItem( i18n("&File"), fileMenu ); |
2079 | popupBarTB->insertItem( i18n("&Edit"), editMenu ); | 2081 | popupBarTB->insertItem( i18n("&Edit"), editMenu ); |
2080 | popupBarTB->insertItem( i18n("&View"), viewMenu ); | 2082 | popupBarTB->insertItem( i18n("&View"), viewMenu ); |
2081 | popupBarTB->insertItem( i18n("&Settings"), settingsMenu ); | 2083 | popupBarTB->insertItem( i18n("&Settings"), settingsMenu ); |
2082 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); | 2084 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); |
2083 | mViewManager->getFilterAction()->plug ( popupBarTB); | 2085 | mViewManager->getFilterAction()->plug ( popupBarTB); |
2084 | //popupBarTB->insertItem( i18n("&Change selected"), changeMenu ); | 2086 | //popupBarTB->insertItem( i18n("&Change selected"), changeMenu ); |
2085 | popupBarTB->insertItem( i18n("&Help"), helpMenu ); | 2087 | popupBarTB->insertItem( i18n("&Help"), helpMenu ); |
2086 | if (QApplication::desktop()->width() > 320 ) { | 2088 | if (QApplication::desktop()->width() > 320 ) { |
2087 | // mViewManager->getFilterAction()->plug ( tb); | 2089 | // mViewManager->getFilterAction()->plug ( tb); |
2088 | } | 2090 | } |
2089 | } | 2091 | } |
2090 | #endif | 2092 | #endif |
2091 | // mActionQuit->plug ( mMainWindow->toolBar()); | 2093 | // mActionQuit->plug ( mMainWindow->toolBar()); |
2092 | 2094 | ||
2093 | 2095 | ||
2094 | 2096 | ||
2095 | //US Now connect the actions with the menue entries. | 2097 | //US Now connect the actions with the menue entries. |
2096 | mActionPrint->plug( fileMenu ); | 2098 | mActionPrint->plug( fileMenu ); |
2097 | mActionMail->plug( fileMenu ); | 2099 | mActionMail->plug( fileMenu ); |
2098 | fileMenu->insertSeparator(); | 2100 | fileMenu->insertSeparator(); |
2099 | 2101 | ||
2100 | mActionNewContact->plug( fileMenu ); | 2102 | mActionNewContact->plug( fileMenu ); |
2101 | mActionNewContact->plug( tb ); | 2103 | mActionNewContact->plug( tb ); |
2102 | 2104 | ||
2103 | mActionEditAddressee->plug( fileMenu ); | 2105 | mActionEditAddressee->plug( fileMenu ); |
2104 | // if ((KGlobal::getDesktopSize() > KGlobal::Small ) || | 2106 | // if ((KGlobal::getDesktopSize() > KGlobal::Small ) || |
2105 | // (!KABPrefs::instance()->mMultipleViewsAtOnce )) | 2107 | // (!KABPrefs::instance()->mMultipleViewsAtOnce )) |
2106 | mActionEditAddressee->plug( tb ); | 2108 | mActionEditAddressee->plug( tb ); |
2107 | 2109 | ||
2108 | fileMenu->insertSeparator(); | 2110 | fileMenu->insertSeparator(); |
2109 | mActionSave->plug( fileMenu ); | 2111 | mActionSave->plug( fileMenu ); |
2110 | fileMenu->insertItem( "&Import", ImportMenu ); | 2112 | fileMenu->insertItem( "&Import", ImportMenu ); |
2111 | fileMenu->insertItem( "&Export", ExportMenu ); | 2113 | fileMenu->insertItem( "&Export", ExportMenu ); |
2112 | fileMenu->insertItem( i18n("&Change"), changeMenu ); | 2114 | fileMenu->insertItem( i18n("&Change"), changeMenu ); |
2113 | #ifndef DESKTOP_VERSION | 2115 | #ifndef DESKTOP_VERSION |
2114 | if ( Ir::supported() ) fileMenu->insertItem( i18n("&Beam"), beamMenu ); | 2116 | if ( Ir::supported() ) fileMenu->insertItem( i18n("&Beam"), beamMenu ); |
2115 | #endif | 2117 | #endif |
2116 | 2118 | ||
2117 | fileMenu->insertSeparator(); | 2119 | fileMenu->insertSeparator(); |
2118 | mActionMailVCard->plug( fileMenu ); | 2120 | mActionMailVCard->plug( fileMenu ); |
2119 | #ifndef DESKTOP_VERSION | 2121 | #ifndef DESKTOP_VERSION |
2120 | if ( Ir::supported() ) mActionBR->plug( beamMenu ); | 2122 | if ( Ir::supported() ) mActionBR->plug( beamMenu ); |
2121 | if ( Ir::supported() ) mActionBeamVCard->plug( beamMenu ); | 2123 | if ( Ir::supported() ) mActionBeamVCard->plug( beamMenu ); |
2122 | if ( Ir::supported() ) mActionBeam->plug( beamMenu ); | 2124 | if ( Ir::supported() ) mActionBeam->plug( beamMenu ); |
2123 | #endif | 2125 | #endif |
2124 | fileMenu->insertSeparator(); | 2126 | fileMenu->insertSeparator(); |
2125 | mActionQuit->plug( fileMenu ); | 2127 | mActionQuit->plug( fileMenu ); |
2126 | #ifdef _WIN32_ | 2128 | #ifdef _WIN32_ |
2127 | mActionImportOL->plug( ImportMenu ); | 2129 | mActionImportOL->plug( ImportMenu ); |
2128 | #endif | 2130 | #endif |
2129 | // edit menu | 2131 | // edit menu |
2130 | mActionUndo->plug( editMenu ); | 2132 | mActionUndo->plug( editMenu ); |
2131 | mActionRedo->plug( editMenu ); | 2133 | mActionRedo->plug( editMenu ); |
2132 | editMenu->insertSeparator(); | 2134 | editMenu->insertSeparator(); |
2133 | mActionCut->plug( editMenu ); | 2135 | mActionCut->plug( editMenu ); |
2134 | mActionCopy->plug( editMenu ); | 2136 | mActionCopy->plug( editMenu ); |
2135 | mActionPaste->plug( editMenu ); | 2137 | mActionPaste->plug( editMenu ); |
2136 | mActionDelete->plug( editMenu ); | 2138 | mActionDelete->plug( editMenu ); |
2137 | editMenu->insertSeparator(); | 2139 | editMenu->insertSeparator(); |
2138 | mActionSelectAll->plug( editMenu ); | 2140 | mActionSelectAll->plug( editMenu ); |
2139 | 2141 | ||
2140 | mActionRemoveVoice->plug( changeMenu ); | 2142 | mActionRemoveVoice->plug( changeMenu ); |
2141 | // settings menu | 2143 | // settings menu |
2142 | //US special menuentry to configure the addressbook resources. On KDE | 2144 | //US special menuentry to configure the addressbook resources. On KDE |
2143 | // you do that through the control center !!! | 2145 | // you do that through the control center !!! |
2144 | mActionConfigResources->plug( settingsMenu ); | 2146 | mActionConfigResources->plug( settingsMenu ); |
2145 | settingsMenu->insertSeparator(); | 2147 | settingsMenu->insertSeparator(); |
2146 | 2148 | ||
2147 | mActionConfigKAddressbook->plug( settingsMenu ); | 2149 | mActionConfigKAddressbook->plug( settingsMenu ); |
2148 | 2150 | ||
2149 | if ( mIsPart ) { | 2151 | if ( mIsPart ) { |
2150 | //US not implemented yet | 2152 | //US not implemented yet |
2151 | //mActionConfigShortcuts->plug( settingsMenu ); | 2153 | //mActionConfigShortcuts->plug( settingsMenu ); |
2152 | //mActionConfigureToolbars->plug( settingsMenu ); | 2154 | //mActionConfigureToolbars->plug( settingsMenu ); |
2153 | 2155 | ||
2154 | } else { | 2156 | } else { |
2155 | //US not implemented yet | 2157 | //US not implemented yet |
2156 | //mActionKeyBindings->plug( settingsMenu ); | 2158 | //mActionKeyBindings->plug( settingsMenu ); |
2157 | } | 2159 | } |
2158 | 2160 | ||
2159 | settingsMenu->insertSeparator(); | 2161 | settingsMenu->insertSeparator(); |
2160 | 2162 | ||
2161 | mActionJumpBar->plug( settingsMenu ); | 2163 | mActionJumpBar->plug( settingsMenu ); |
2162 | mActionDetails->plug( settingsMenu ); | 2164 | mActionDetails->plug( settingsMenu ); |
2163 | //if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) | 2165 | //if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) |
2164 | mActionDetails->plug( tb ); | 2166 | mActionDetails->plug( tb ); |
2165 | settingsMenu->insertSeparator(); | 2167 | settingsMenu->insertSeparator(); |
2166 | #ifndef DESKTOP_VERSION | 2168 | #ifndef DESKTOP_VERSION |
2167 | if ( Ir::supported() ) mActionBR->plug(settingsMenu ); | 2169 | if ( Ir::supported() ) mActionBR->plug(settingsMenu ); |
2168 | #endif | 2170 | #endif |
2169 | settingsMenu->insertSeparator(); | 2171 | settingsMenu->insertSeparator(); |
2170 | 2172 | ||
2171 | mActionWhoAmI->plug( settingsMenu ); | 2173 | mActionWhoAmI->plug( settingsMenu ); |
2172 | mActionEditCategories->plug( settingsMenu ); | 2174 | mActionEditCategories->plug( settingsMenu ); |
2173 | mActionEditCategories->plug( changeMenu ); | 2175 | mActionEditCategories->plug( changeMenu ); |
2174 | mActionCategories->plug( changeMenu ); | 2176 | mActionCategories->plug( changeMenu ); |
2175 | mActionManageCategories->plug( changeMenu ); | 2177 | mActionManageCategories->plug( changeMenu ); |
2176 | 2178 | ||
2177 | mActionCategories->plug( settingsMenu ); | 2179 | mActionCategories->plug( settingsMenu ); |
2178 | mActionManageCategories->plug( settingsMenu ); | 2180 | mActionManageCategories->plug( settingsMenu ); |
2179 | 2181 | ||
2180 | 2182 | ||
2181 | mActionWN->plug( helpMenu ); | 2183 | mActionWN->plug( helpMenu ); |
@@ -2625,548 +2627,552 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i | |||
2625 | } | 2627 | } |
2626 | 2628 | ||
2627 | } | 2629 | } |
2628 | } | 2630 | } |
2629 | full = true; | 2631 | full = true; |
2630 | if ( mode < SYNC_PREF_ASK ) | 2632 | if ( mode < SYNC_PREF_ASK ) |
2631 | mode = SYNC_PREF_ASK; | 2633 | mode = SYNC_PREF_ASK; |
2632 | } else { | 2634 | } else { |
2633 | if ( localMod == remoteMod ) | 2635 | if ( localMod == remoteMod ) |
2634 | return 0; | 2636 | return 0; |
2635 | 2637 | ||
2636 | } | 2638 | } |
2637 | //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); | 2639 | //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); |
2638 | //qDebug("lastsync %s ", lastSync.toString().latin1() ); | 2640 | //qDebug("lastsync %s ", lastSync.toString().latin1() ); |
2639 | //full = true; //debug only | 2641 | //full = true; //debug only |
2640 | if ( full ) { | 2642 | if ( full ) { |
2641 | bool equ = ( (*local) == (*remote) ); | 2643 | bool equ = ( (*local) == (*remote) ); |
2642 | if ( equ ) { | 2644 | if ( equ ) { |
2643 | //qDebug("equal "); | 2645 | //qDebug("equal "); |
2644 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2646 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2645 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2647 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2646 | } | 2648 | } |
2647 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2649 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2648 | return 0; | 2650 | return 0; |
2649 | 2651 | ||
2650 | }//else //debug only | 2652 | }//else //debug only |
2651 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2653 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2652 | } | 2654 | } |
2653 | int result; | 2655 | int result; |
2654 | bool localIsNew; | 2656 | bool localIsNew; |
2655 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 2657 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
2656 | 2658 | ||
2657 | if ( full && mode < SYNC_PREF_NEWEST ) | 2659 | if ( full && mode < SYNC_PREF_NEWEST ) |
2658 | mode = SYNC_PREF_ASK; | 2660 | mode = SYNC_PREF_ASK; |
2659 | 2661 | ||
2660 | switch( mode ) { | 2662 | switch( mode ) { |
2661 | case SYNC_PREF_LOCAL: | 2663 | case SYNC_PREF_LOCAL: |
2662 | if ( lastSync > remoteMod ) | 2664 | if ( lastSync > remoteMod ) |
2663 | return 1; | 2665 | return 1; |
2664 | if ( lastSync > localMod ) | 2666 | if ( lastSync > localMod ) |
2665 | return 2; | 2667 | return 2; |
2666 | return 1; | 2668 | return 1; |
2667 | break; | 2669 | break; |
2668 | case SYNC_PREF_REMOTE: | 2670 | case SYNC_PREF_REMOTE: |
2669 | if ( lastSync > remoteMod ) | 2671 | if ( lastSync > remoteMod ) |
2670 | return 1; | 2672 | return 1; |
2671 | if ( lastSync > localMod ) | 2673 | if ( lastSync > localMod ) |
2672 | return 2; | 2674 | return 2; |
2673 | return 2; | 2675 | return 2; |
2674 | break; | 2676 | break; |
2675 | case SYNC_PREF_NEWEST: | 2677 | case SYNC_PREF_NEWEST: |
2676 | if ( localMod > remoteMod ) | 2678 | if ( localMod > remoteMod ) |
2677 | return 1; | 2679 | return 1; |
2678 | else | 2680 | else |
2679 | return 2; | 2681 | return 2; |
2680 | break; | 2682 | break; |
2681 | case SYNC_PREF_ASK: | 2683 | case SYNC_PREF_ASK: |
2682 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 2684 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
2683 | if ( lastSync > remoteMod ) | 2685 | if ( lastSync > remoteMod ) |
2684 | return 1; | 2686 | return 1; |
2685 | if ( lastSync > localMod ) | 2687 | if ( lastSync > localMod ) |
2686 | return 2; | 2688 | return 2; |
2687 | localIsNew = localMod >= remoteMod; | 2689 | localIsNew = localMod >= remoteMod; |
2688 | //qDebug("conflict! ************************************** "); | 2690 | //qDebug("conflict! ************************************** "); |
2689 | { | 2691 | { |
2690 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2692 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2691 | result = acd.executeD(localIsNew); | 2693 | result = acd.executeD(localIsNew); |
2692 | return result; | 2694 | return result; |
2693 | } | 2695 | } |
2694 | break; | 2696 | break; |
2695 | case SYNC_PREF_FORCE_LOCAL: | 2697 | case SYNC_PREF_FORCE_LOCAL: |
2696 | return 1; | 2698 | return 1; |
2697 | break; | 2699 | break; |
2698 | case SYNC_PREF_FORCE_REMOTE: | 2700 | case SYNC_PREF_FORCE_REMOTE: |
2699 | return 2; | 2701 | return 2; |
2700 | break; | 2702 | break; |
2701 | 2703 | ||
2702 | default: | 2704 | default: |
2703 | // SYNC_PREF_TAKE_BOTH not implemented | 2705 | // SYNC_PREF_TAKE_BOTH not implemented |
2704 | break; | 2706 | break; |
2705 | } | 2707 | } |
2706 | return 0; | 2708 | return 0; |
2707 | } | 2709 | } |
2708 | 2710 | ||
2709 | 2711 | ||
2710 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2712 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2711 | { | 2713 | { |
2712 | bool syncOK = true; | 2714 | bool syncOK = true; |
2713 | int addedAddressee = 0; | 2715 | int addedAddressee = 0; |
2714 | int addedAddresseeR = 0; | 2716 | int addedAddresseeR = 0; |
2715 | int deletedAddresseeR = 0; | 2717 | int deletedAddresseeR = 0; |
2716 | int deletedAddresseeL = 0; | 2718 | int deletedAddresseeL = 0; |
2717 | int changedLocal = 0; | 2719 | int changedLocal = 0; |
2718 | int changedRemote = 0; | 2720 | int changedRemote = 0; |
2719 | 2721 | ||
2720 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | 2722 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); |
2721 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2723 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2722 | 2724 | ||
2723 | //QPtrList<Addressee> el = local->rawAddressees(); | 2725 | //QPtrList<Addressee> el = local->rawAddressees(); |
2724 | Addressee addresseeR; | 2726 | Addressee addresseeR; |
2725 | QString uid; | 2727 | QString uid; |
2726 | int take; | 2728 | int take; |
2727 | Addressee addresseeL; | 2729 | Addressee addresseeL; |
2728 | Addressee addresseeRSync; | 2730 | Addressee addresseeRSync; |
2729 | Addressee addresseeLSync; | 2731 | Addressee addresseeLSync; |
2730 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2732 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2731 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2733 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2732 | bool fullDateRange = false; | 2734 | bool fullDateRange = false; |
2733 | local->resetTempSyncStat(); | 2735 | local->resetTempSyncStat(); |
2734 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2736 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2735 | if ( syncManager->syncWithDesktop() ) { | 2737 | if ( syncManager->syncWithDesktop() ) { |
2736 | // remote->removeSyncInfo( QString());//remove all info | 2738 | // remote->removeSyncInfo( QString());//remove all info |
2737 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 2739 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
2738 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; | 2740 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; |
2739 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); | 2741 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); |
2740 | } else { | 2742 | } else { |
2741 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 2743 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
2742 | } | 2744 | } |
2743 | } | 2745 | } |
2744 | QDateTime modifiedCalendar = mLastAddressbookSync; | 2746 | QDateTime modifiedCalendar = mLastAddressbookSync; |
2745 | addresseeLSync = getLastSyncAddressee(); | 2747 | addresseeLSync = getLastSyncAddressee(); |
2746 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2748 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2747 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2749 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2748 | if ( !addresseeR.isEmpty() ) { | 2750 | if ( !addresseeR.isEmpty() ) { |
2749 | addresseeRSync = addresseeR; | 2751 | addresseeRSync = addresseeR; |
2750 | remote->removeAddressee(addresseeR ); | 2752 | remote->removeAddressee(addresseeR ); |
2751 | 2753 | ||
2752 | } else { | 2754 | } else { |
2753 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2755 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2754 | addresseeRSync = addresseeLSync ; | 2756 | addresseeRSync = addresseeLSync ; |
2755 | } else { | 2757 | } else { |
2756 | //qDebug("FULLDATE 1"); | 2758 | //qDebug("FULLDATE 1"); |
2757 | fullDateRange = true; | 2759 | fullDateRange = true; |
2758 | Addressee newAdd; | 2760 | Addressee newAdd; |
2759 | addresseeRSync = newAdd; | 2761 | addresseeRSync = newAdd; |
2760 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2762 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2761 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2763 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2762 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2764 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2763 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2765 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2764 | } | 2766 | } |
2765 | } | 2767 | } |
2766 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2768 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2767 | // qDebug("FULLDATE 2"); | 2769 | // qDebug("FULLDATE 2"); |
2768 | fullDateRange = true; | 2770 | fullDateRange = true; |
2769 | } | 2771 | } |
2770 | if ( ! fullDateRange ) { | 2772 | if ( ! fullDateRange ) { |
2771 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2773 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2772 | 2774 | ||
2773 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2775 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2774 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2776 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2775 | fullDateRange = true; | 2777 | fullDateRange = true; |
2776 | //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2778 | //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2777 | } | 2779 | } |
2778 | } | 2780 | } |
2779 | // fullDateRange = true; // debug only! | 2781 | // fullDateRange = true; // debug only! |
2780 | if ( fullDateRange ) | 2782 | if ( fullDateRange ) |
2781 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2783 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2782 | else | 2784 | else |
2783 | mLastAddressbookSync = addresseeLSync.revision(); | 2785 | mLastAddressbookSync = addresseeLSync.revision(); |
2784 | // for resyncing if own file has changed | 2786 | // for resyncing if own file has changed |
2785 | // PENDING fixme later when implemented | 2787 | // PENDING fixme later when implemented |
2786 | #if 0 | 2788 | #if 0 |
2787 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2789 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2788 | mLastAddressbookSync = loadedFileVersion; | 2790 | mLastAddressbookSync = loadedFileVersion; |
2789 | qDebug("setting mLastAddressbookSync "); | 2791 | qDebug("setting mLastAddressbookSync "); |
2790 | } | 2792 | } |
2791 | #endif | 2793 | #endif |
2792 | 2794 | ||
2793 | //qDebug("*************************** "); | 2795 | //qDebug("*************************** "); |
2794 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2796 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2795 | QStringList er = remote->uidList(); | 2797 | QStringList er = remote->uidList(); |
2796 | Addressee inR ;//= er.first(); | 2798 | Addressee inR ;//= er.first(); |
2797 | Addressee inL; | 2799 | Addressee inL; |
2798 | 2800 | ||
2799 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2801 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2800 | 2802 | ||
2801 | int modulo = (er.count()/10)+1; | 2803 | int modulo = (er.count()/10)+1; |
2802 | int incCounter = 0; | 2804 | int incCounter = 0; |
2803 | while ( incCounter < er.count()) { | 2805 | while ( incCounter < er.count()) { |
2804 | if (syncManager->isProgressBarCanceled()) | 2806 | if (syncManager->isProgressBarCanceled()) |
2805 | return false; | 2807 | return false; |
2806 | if ( incCounter % modulo == 0 ) | 2808 | if ( incCounter % modulo == 0 ) |
2807 | syncManager->showProgressBar(incCounter); | 2809 | syncManager->showProgressBar(incCounter); |
2808 | 2810 | ||
2809 | uid = er[ incCounter ]; | 2811 | uid = er[ incCounter ]; |
2810 | bool skipIncidence = false; | 2812 | bool skipIncidence = false; |
2811 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2813 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2812 | skipIncidence = true; | 2814 | skipIncidence = true; |
2813 | QString idS,OidS; | 2815 | QString idS,OidS; |
2814 | qApp->processEvents(); | 2816 | qApp->processEvents(); |
2815 | if ( !skipIncidence ) { | 2817 | if ( !skipIncidence ) { |
2816 | inL = local->findByUid( uid ); | 2818 | inL = local->findByUid( uid ); |
2817 | inR = remote->findByUid( uid ); | 2819 | inR = remote->findByUid( uid ); |
2818 | //inL.setResource( 0 ); | 2820 | //inL.setResource( 0 ); |
2819 | //inR.setResource( 0 ); | 2821 | //inR.setResource( 0 ); |
2820 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2822 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2821 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2823 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2822 | if ( (take = takeAddressee( &inL, &inR, mode, fullDateRange )) ) { | 2824 | if ( (take = takeAddressee( &inL, &inR, mode, fullDateRange )) ) { |
2823 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2825 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2824 | if ( take == 3 ) | 2826 | if ( take == 3 ) |
2825 | return false; | 2827 | return false; |
2826 | if ( take == 1 ) {// take local ********************** | 2828 | if ( take == 1 ) {// take local ********************** |
2827 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2829 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2828 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2830 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2829 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2831 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2830 | local->insertAddressee( inL, false ); | 2832 | local->insertAddressee( inL, false ); |
2831 | idS = inR.externalUID(); | 2833 | idS = inR.externalUID(); |
2832 | OidS = inR.originalExternalUID(); | 2834 | OidS = inR.originalExternalUID(); |
2833 | } | 2835 | } |
2834 | else | 2836 | else |
2835 | idS = inR.IDStr(); | 2837 | idS = inR.IDStr(); |
2836 | remote->removeAddressee( inR ); | 2838 | remote->removeAddressee( inR ); |
2837 | inR = inL; | 2839 | inR = inL; |
2838 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2840 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2839 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2841 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2840 | inR.setOriginalExternalUID( OidS ); | 2842 | inR.setOriginalExternalUID( OidS ); |
2841 | inR.setExternalUID( idS ); | 2843 | inR.setExternalUID( idS ); |
2842 | if ( syncManager->syncWithDesktop() ) { | 2844 | if ( syncManager->syncWithDesktop() ) { |
2843 | inR.setIDStr("changed" ); | 2845 | inR.setIDStr("changed" ); |
2844 | } | 2846 | } |
2845 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); | 2847 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); |
2846 | } else { | 2848 | } else { |
2847 | inR.setIDStr( idS ); | 2849 | inR.setIDStr( idS ); |
2848 | } | 2850 | } |
2849 | inR.setResource( 0 ); | 2851 | inR.setResource( 0 ); |
2850 | remote->insertAddressee( inR , false); | 2852 | remote->insertAddressee( inR , false); |
2851 | ++changedRemote; | 2853 | ++changedRemote; |
2852 | } else { // take == 2 take remote ********************** | 2854 | } else { // take == 2 take remote ********************** |
2853 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2855 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2854 | if ( inR.revision().date().year() < 2004 ) | 2856 | if ( inR.revision().date().year() < 2004 ) |
2855 | inR.setRevision( modifiedCalendar ); | 2857 | inR.setRevision( modifiedCalendar ); |
2856 | } | 2858 | } |
2857 | idS = inL.IDStr(); | 2859 | idS = inL.IDStr(); |
2858 | local->removeAddressee( inL ); | 2860 | local->removeAddressee( inL ); |
2859 | inL = inR; | 2861 | inL = inR; |
2860 | inL.setIDStr( idS ); | 2862 | inL.setIDStr( idS ); |
2861 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2863 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2862 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2864 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2863 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2865 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2864 | } | 2866 | } |
2865 | inL.setResource( 0 ); | 2867 | inL.setResource( 0 ); |
2866 | local->insertAddressee( inL , false ); | 2868 | local->insertAddressee( inL , false ); |
2867 | ++changedLocal; | 2869 | ++changedLocal; |
2868 | } | 2870 | } |
2869 | } | 2871 | } |
2870 | } | 2872 | } |
2871 | } else { // no conflict ********** add or delete remote | 2873 | } else { // no conflict ********** add or delete remote |
2872 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2874 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2873 | QString des = addresseeLSync.note(); | 2875 | QString des = addresseeLSync.note(); |
2874 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2876 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2875 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2877 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2876 | remote->insertAddressee( inR, false ); | 2878 | remote->insertAddressee( inR, false ); |
2877 | ++deletedAddresseeR; | 2879 | ++deletedAddresseeR; |
2878 | } else { | 2880 | } else { |
2879 | inR.setRevision( modifiedCalendar ); | 2881 | inR.setRevision( modifiedCalendar ); |
2880 | remote->insertAddressee( inR, false ); | 2882 | remote->insertAddressee( inR, false ); |
2881 | inL = inR; | 2883 | inL = inR; |
2882 | inL.setIDStr( ":" ); | 2884 | inL.setIDStr( ":" ); |
2883 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2885 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2884 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2886 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2885 | inL.setResource( 0 ); | 2887 | inL.setResource( 0 ); |
2886 | local->insertAddressee( inL , false); | 2888 | local->insertAddressee( inL , false); |
2887 | ++addedAddressee; | 2889 | ++addedAddressee; |
2888 | } | 2890 | } |
2889 | } else { | 2891 | } else { |
2890 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2892 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2891 | inR.setRevision( modifiedCalendar ); | 2893 | inR.setRevision( modifiedCalendar ); |
2892 | remote->insertAddressee( inR, false ); | 2894 | remote->insertAddressee( inR, false ); |
2893 | inR.setResource( 0 ); | 2895 | inR.setResource( 0 ); |
2894 | local->insertAddressee( inR, false ); | 2896 | local->insertAddressee( inR, false ); |
2895 | ++addedAddressee; | 2897 | ++addedAddressee; |
2896 | } else { | 2898 | } else { |
2897 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2899 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2898 | remote->removeAddressee( inR ); | 2900 | remote->removeAddressee( inR ); |
2899 | ++deletedAddresseeR; | 2901 | ++deletedAddresseeR; |
2900 | } | 2902 | } |
2901 | } | 2903 | } |
2902 | } | 2904 | } |
2903 | } | 2905 | } |
2904 | ++incCounter; | 2906 | ++incCounter; |
2905 | } | 2907 | } |
2906 | er.clear(); | 2908 | er.clear(); |
2907 | QStringList el = local->uidList(); | 2909 | QStringList el = local->uidList(); |
2908 | modulo = (el.count()/10)+1; | 2910 | modulo = (el.count()/10)+1; |
2909 | 2911 | ||
2910 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2912 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2911 | incCounter = 0; | 2913 | incCounter = 0; |
2912 | while ( incCounter < el.count()) { | 2914 | while ( incCounter < el.count()) { |
2913 | qApp->processEvents(); | 2915 | qApp->processEvents(); |
2914 | if (syncManager->isProgressBarCanceled()) | 2916 | if (syncManager->isProgressBarCanceled()) |
2915 | return false; | 2917 | return false; |
2916 | if ( incCounter % modulo == 0 ) | 2918 | if ( incCounter % modulo == 0 ) |
2917 | syncManager->showProgressBar(incCounter); | 2919 | syncManager->showProgressBar(incCounter); |
2918 | uid = el[ incCounter ]; | 2920 | uid = el[ incCounter ]; |
2919 | bool skipIncidence = false; | 2921 | bool skipIncidence = false; |
2920 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2922 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2921 | skipIncidence = true; | 2923 | skipIncidence = true; |
2922 | if ( !skipIncidence ) { | 2924 | if ( !skipIncidence ) { |
2923 | inL = local->findByUid( uid ); | 2925 | inL = local->findByUid( uid ); |
2924 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2926 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2925 | inR = remote->findByUid( uid ); | 2927 | inR = remote->findByUid( uid ); |
2926 | if ( inR.isEmpty() ) { // no conflict ********** add or delete local | 2928 | if ( inR.isEmpty() ) { // no conflict ********** add or delete local |
2927 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2929 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2928 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2930 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2929 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2931 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2930 | local->removeAddressee( inL ); | 2932 | local->removeAddressee( inL ); |
2931 | ++deletedAddresseeL; | 2933 | ++deletedAddresseeL; |
2932 | } else { | 2934 | } else { |
2933 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2935 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2934 | inL.removeID(mCurrentSyncDevice ); | 2936 | inL.removeID(mCurrentSyncDevice ); |
2935 | ++addedAddresseeR; | 2937 | ++addedAddresseeR; |
2936 | inL.setRevision( modifiedCalendar ); | 2938 | inL.setRevision( modifiedCalendar ); |
2937 | local->insertAddressee( inL, false ); | 2939 | local->insertAddressee( inL, false ); |
2938 | inR = inL; | 2940 | inR = inL; |
2939 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2941 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2940 | inR.setResource( 0 ); | 2942 | inR.setResource( 0 ); |
2941 | remote->insertAddressee( inR, false ); | 2943 | remote->insertAddressee( inR, false ); |
2942 | } | 2944 | } |
2943 | } | 2945 | } |
2944 | } else { | 2946 | } else { |
2945 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2947 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2946 | //qDebug("data %s ", inL.revision().toString().latin1()); | 2948 | //qDebug("data %s ", inL.revision().toString().latin1()); |
2947 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2949 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2948 | local->removeAddressee( inL ); | 2950 | local->removeAddressee( inL ); |
2949 | ++deletedAddresseeL; | 2951 | ++deletedAddresseeL; |
2950 | } else { | 2952 | } else { |
2951 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2953 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2952 | ++addedAddresseeR; | 2954 | ++addedAddresseeR; |
2953 | inL.setRevision( modifiedCalendar ); | 2955 | inL.setRevision( modifiedCalendar ); |
2954 | local->insertAddressee( inL, false ); | 2956 | local->insertAddressee( inL, false ); |
2955 | inR = inL; | 2957 | inR = inL; |
2956 | inR.setIDStr( ":" ); | 2958 | inR.setIDStr( ":" ); |
2957 | inR.setResource( 0 ); | 2959 | inR.setResource( 0 ); |
2958 | remote->insertAddressee( inR, false ); | 2960 | remote->insertAddressee( inR, false ); |
2959 | } | 2961 | } |
2960 | } | 2962 | } |
2961 | } | 2963 | } |
2962 | } | 2964 | } |
2963 | } | 2965 | } |
2964 | } | 2966 | } |
2965 | ++incCounter; | 2967 | ++incCounter; |
2966 | } | 2968 | } |
2967 | el.clear(); | 2969 | el.clear(); |
2968 | syncManager->hideProgressBar(); | 2970 | syncManager->hideProgressBar(); |
2969 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2971 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2970 | // get rid of micro seconds | 2972 | // get rid of micro seconds |
2971 | QTime t = mLastAddressbookSync.time(); | 2973 | QTime t = mLastAddressbookSync.time(); |
2972 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2974 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2973 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2975 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2974 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2976 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2975 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2977 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2976 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2978 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2977 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2979 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2978 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2980 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2979 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2981 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2980 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2982 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2981 | addresseeRSync.setNote( "" ) ; | 2983 | addresseeRSync.setNote( "" ) ; |
2982 | addresseeLSync.setNote( "" ); | 2984 | addresseeLSync.setNote( "" ); |
2983 | 2985 | ||
2984 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2986 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2985 | remote->insertAddressee( addresseeRSync, false ); | 2987 | remote->insertAddressee( addresseeRSync, false ); |
2986 | local->insertAddressee( addresseeLSync, false ); | 2988 | local->insertAddressee( addresseeLSync, false ); |
2987 | QString mes; | 2989 | QString mes; |
2988 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); | 2990 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); |
2989 | qDebug( mes ); | 2991 | qDebug( mes ); |
2990 | mes = i18n("Local addressbook changed!\n") +mes; | 2992 | mes = i18n("Local addressbook changed!\n") +mes; |
2991 | if ( syncManager->mShowSyncSummary ) { | 2993 | if ( syncManager->mShowSyncSummary ) { |
2992 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 2994 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
2993 | i18n("KA/Pi Synchronization"),i18n("Write back"))) { | 2995 | i18n("KA/Pi Synchronization"),i18n("Write back"))) { |
2994 | qDebug("cancelled "); | 2996 | qDebug("cancelled "); |
2995 | return false; | 2997 | return false; |
2996 | } | 2998 | } |
2997 | } | 2999 | } |
2998 | return syncOK; | 3000 | return syncOK; |
2999 | } | 3001 | } |
3000 | 3002 | ||
3001 | 3003 | ||
3002 | //this is a overwritten callbackmethods from the syncinterface | 3004 | //this is a overwritten callbackmethods from the syncinterface |
3003 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 3005 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
3004 | { | 3006 | { |
3005 | 3007 | ||
3006 | //pending prepare addresseeview for output | 3008 | //pending prepare addresseeview for output |
3007 | //pending detect, if remote file has REV field. if not switch to external sync | 3009 | //pending detect, if remote file has REV field. if not switch to external sync |
3008 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 3010 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
3011 | if ( manager != syncManager ) | ||
3012 | qDebug("KABCore::sync:: ERROR! :: manager != syncManager "); | ||
3009 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3013 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3010 | 3014 | ||
3011 | AddressBook abLocal(filename,"syncContact"); | 3015 | AddressBook abLocal(filename,"syncContact"); |
3012 | bool syncOK = false; | 3016 | bool syncOK = false; |
3013 | if ( abLocal.load() ) { | 3017 | if ( abLocal.load() ) { |
3014 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 3018 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
3015 | bool external = false; | 3019 | bool external = false; |
3016 | bool isXML = false; | 3020 | bool isXML = false; |
3017 | if ( filename.right(4) == ".xml") { | 3021 | if ( filename.right(4) == ".xml") { |
3018 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3022 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3019 | isXML = true; | 3023 | isXML = true; |
3020 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 3024 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
3021 | } else { | 3025 | } else { |
3022 | external = !manager->mIsKapiFile; | 3026 | external = !manager->mIsKapiFile; |
3023 | if ( external ) { | 3027 | if ( external ) { |
3024 | qDebug("Setting vcf mode to external "); | 3028 | qDebug("Setting vcf mode to external "); |
3025 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3029 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3026 | AddressBook::Iterator it; | 3030 | AddressBook::Iterator it; |
3027 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 3031 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
3028 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 3032 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
3029 | (*it).computeCsum( mCurrentSyncDevice ); | 3033 | (*it).computeCsum( mCurrentSyncDevice ); |
3030 | } | 3034 | } |
3031 | } | 3035 | } |
3032 | } | 3036 | } |
3033 | //AddressBook::Iterator it; | 3037 | //AddressBook::Iterator it; |
3034 | //QStringList vcards; | 3038 | //QStringList vcards; |
3035 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 3039 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
3036 | // qDebug("Name %s ", (*it).familyName().latin1()); | 3040 | // qDebug("Name %s ", (*it).familyName().latin1()); |
3037 | //} | 3041 | //} |
3038 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 3042 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
3039 | if ( syncOK ) { | 3043 | if ( syncOK ) { |
3040 | if ( syncManager->mWriteBackFile ) | 3044 | if ( syncManager->mWriteBackFile ) |
3041 | { | 3045 | { |
3042 | if ( external ) | 3046 | if ( external ) |
3043 | abLocal.removeSyncAddressees( !isXML); | 3047 | abLocal.removeSyncAddressees( !isXML); |
3044 | qDebug("Saving remote AB "); | 3048 | qDebug("Saving remote AB "); |
3045 | if ( ! abLocal.saveAB()) | 3049 | if ( ! abLocal.saveAB()) |
3046 | qDebug("Error writing back AB to file "); | 3050 | qDebug("Error writing back AB to file "); |
3047 | if ( external ) { | 3051 | if ( external ) { |
3048 | // afterwrite processing | 3052 | // afterwrite processing |
3049 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); | 3053 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); |
3050 | } | 3054 | } |
3051 | } | 3055 | } |
3052 | } | 3056 | } |
3053 | setModified(); | 3057 | setModified(); |
3054 | 3058 | ||
3055 | } | 3059 | } |
3056 | abLocal.removeResources(); | 3060 | abLocal.removeResources(); |
3057 | if ( syncOK ) | 3061 | if ( syncOK ) |
3058 | mViewManager->refreshView(); | 3062 | mViewManager->refreshView(); |
3059 | return syncOK; | 3063 | return syncOK; |
3060 | 3064 | ||
3061 | } | 3065 | } |
3062 | void KABCore::removeSyncInfo( QString syncProfile) | 3066 | void KABCore::removeSyncInfo( QString syncProfile) |
3063 | { | 3067 | { |
3064 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); | 3068 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); |
3065 | mAddressBook->removeSyncInfo( syncProfile ); | 3069 | mAddressBook->removeSyncInfo( syncProfile ); |
3066 | setModified(); | 3070 | setModified(); |
3067 | } | 3071 | } |
3068 | 3072 | ||
3069 | 3073 | ||
3070 | //this is a overwritten callbackmethods from the syncinterface | 3074 | //this is a overwritten callbackmethods from the syncinterface |
3071 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 3075 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
3072 | { | 3076 | { |
3073 | if ( resource == "phone" ) | 3077 | if ( resource == "phone" ) |
3074 | return syncPhone(); | 3078 | return syncPhone(); |
3075 | disableBR( true ); | 3079 | disableBR( true ); |
3080 | if ( manager != syncManager ) | ||
3081 | qDebug("KABCore::syncExternal:: ERROR! :: manager != syncManager "); | ||
3076 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3082 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3077 | 3083 | ||
3078 | AddressBook abLocal( resource,"syncContact"); | 3084 | AddressBook abLocal( resource,"syncContact"); |
3079 | bool syncOK = false; | 3085 | bool syncOK = false; |
3080 | if ( abLocal.load() ) { | 3086 | if ( abLocal.load() ) { |
3081 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 3087 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
3082 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3088 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3083 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); | 3089 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); |
3084 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 3090 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
3085 | if ( syncOK ) { | 3091 | if ( syncOK ) { |
3086 | if ( syncManager->mWriteBackFile ) { | 3092 | if ( syncManager->mWriteBackFile ) { |
3087 | abLocal.removeSyncAddressees( false ); | 3093 | abLocal.removeSyncAddressees( false ); |
3088 | abLocal.saveAB(); | 3094 | abLocal.saveAB(); |
3089 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); | 3095 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
3090 | } | 3096 | } |
3091 | } else | 3097 | } else |
3092 | message( i18n("Sync cancelled or failed.") ); | 3098 | message( i18n("Sync cancelled or failed.") ); |
3093 | setModified(); | 3099 | setModified(); |
3094 | } | 3100 | } |
3095 | abLocal.removeResources(); | 3101 | abLocal.removeResources(); |
3096 | if ( syncOK ) | 3102 | if ( syncOK ) |
3097 | mViewManager->refreshView(); | 3103 | mViewManager->refreshView(); |
3098 | disableBR( false ); | 3104 | disableBR( false ); |
3099 | return syncOK; | 3105 | return syncOK; |
3100 | 3106 | ||
3101 | } | 3107 | } |
3102 | void KABCore::message( QString m ) | 3108 | void KABCore::message( QString m ) |
3103 | { | 3109 | { |
3104 | topLevelWidget()->setCaption( m ); | 3110 | topLevelWidget()->setCaption( m ); |
3105 | mMessageTimer->start( 15000, true ); | 3111 | mMessageTimer->start( 15000, true ); |
3106 | } | 3112 | } |
3107 | bool KABCore::syncPhone() | 3113 | bool KABCore::syncPhone() |
3108 | { | 3114 | { |
3109 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 3115 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
3110 | QString fileName = getPhoneFile(); | 3116 | QString fileName = getPhoneFile(); |
3111 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 3117 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
3112 | message(i18n("Phone access failed!")); | 3118 | message(i18n("Phone access failed!")); |
3113 | return false; | 3119 | return false; |
3114 | } | 3120 | } |
3115 | AddressBook abLocal( fileName,"syncContact"); | 3121 | AddressBook abLocal( fileName,"syncContact"); |
3116 | bool syncOK = false; | 3122 | bool syncOK = false; |
3117 | { | 3123 | { |
3118 | abLocal.importFromFile( fileName ); | 3124 | abLocal.importFromFile( fileName ); |
3119 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 3125 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
3120 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3126 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3121 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | 3127 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); |
3122 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 3128 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
3123 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 3129 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
3124 | if ( syncOK ) { | 3130 | if ( syncOK ) { |
3125 | if ( syncManager->mWriteBackFile ) { | 3131 | if ( syncManager->mWriteBackFile ) { |
3126 | abLocal.removeSyncAddressees( true ); | 3132 | abLocal.removeSyncAddressees( true ); |
3127 | abLocal.saveABphone( fileName ); | 3133 | abLocal.saveABphone( fileName ); |
3128 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); | 3134 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); |
3129 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | 3135 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); |
3130 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); | 3136 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
3131 | } | 3137 | } |
3132 | } | 3138 | } |
3133 | setModified(); | 3139 | setModified(); |
3134 | } | 3140 | } |
3135 | abLocal.removeResources(); | 3141 | abLocal.removeResources(); |
3136 | if ( syncOK ) | 3142 | if ( syncOK ) |
3137 | mViewManager->refreshView(); | 3143 | mViewManager->refreshView(); |
3138 | return syncOK; | 3144 | return syncOK; |
3139 | } | 3145 | } |
3140 | void KABCore::getFile( bool success ) | 3146 | void KABCore::getFile( bool success ) |
3141 | { | 3147 | { |
3142 | if ( ! success ) { | 3148 | if ( ! success ) { |
3143 | message( i18n("Error receiving file. Nothing changed!") ); | 3149 | message( i18n("Error receiving file. Nothing changed!") ); |
3144 | return; | 3150 | return; |
3145 | } | 3151 | } |
3146 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); | 3152 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); |
3147 | if ( count ) | 3153 | if ( count ) |
3148 | setModified( true ); | 3154 | setModified( true ); |
3149 | message( i18n("Pi-Sync successful!") ); | 3155 | message( i18n("Pi-Sync successful!") ); |
3150 | mViewManager->refreshView(); | 3156 | mViewManager->refreshView(); |
3151 | } | 3157 | } |
3152 | void KABCore::syncFileRequest() | 3158 | void KABCore::syncFileRequest() |
3153 | { | 3159 | { |
3154 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { | 3160 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { |
3155 | syncManager->slotSyncMenu( 999 ); | 3161 | syncManager->slotSyncMenu( 999 ); |
3156 | } | 3162 | } |
3157 | mAddressBook->export2File( sentSyncFile() ); | 3163 | mAddressBook->export2File( sentSyncFile() ); |
3158 | } | 3164 | } |
3159 | QString KABCore::sentSyncFile() | 3165 | QString KABCore::sentSyncFile() |
3160 | { | 3166 | { |
3161 | #ifdef DESKTOP_VERSION | 3167 | #ifdef DESKTOP_VERSION |
3162 | return locateLocal( "tmp", "copysyncab.vcf" ); | 3168 | return locateLocal( "tmp", "copysyncab.vcf" ); |
3163 | #else | 3169 | #else |
3164 | return QString( "/tmp/copysyncab.vcf" ); | 3170 | return QString( "/tmp/copysyncab.vcf" ); |
3165 | #endif | 3171 | #endif |
3166 | } | 3172 | } |
3167 | 3173 | ||
3168 | void KABCore::setCaptionBack() | 3174 | void KABCore::setCaptionBack() |
3169 | { | 3175 | { |
3170 | mMessageTimer->stop(); | 3176 | mMessageTimer->stop(); |
3171 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 3177 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
3172 | } | 3178 | } |
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index c12ba1c..7c53948 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -19,769 +19,769 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | // $Id$ | 21 | // $Id$ |
22 | 22 | ||
23 | #include "ksyncmanager.h" | 23 | #include "ksyncmanager.h" |
24 | 24 | ||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | 26 | ||
27 | #ifndef _WIN32_ | 27 | #ifndef _WIN32_ |
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | 31 | ||
32 | #include "ksyncprofile.h" | 32 | #include "ksyncprofile.h" |
33 | #include "ksyncprefsdialog.h" | 33 | #include "ksyncprefsdialog.h" |
34 | #include "kpimprefs.h" | 34 | #include "kpimprefs.h" |
35 | #include <kmessagebox.h> | 35 | #include <kmessagebox.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qprogressbar.h> | 38 | #include <qprogressbar.h> |
39 | #include <qpopupmenu.h> | 39 | #include <qpopupmenu.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qbuttongroup.h> | 42 | #include <qbuttongroup.h> |
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
45 | #include <qapplication.h> | 45 | #include <qapplication.h> |
46 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
47 | #include <qdialog.h> | 47 | #include <qdialog.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qtextcodec.h> | 49 | #include <qtextcodec.h> |
50 | #include <qlabel.h> | 50 | #include <qlabel.h> |
51 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
52 | 52 | ||
53 | #include <klocale.h> | 53 | #include <klocale.h> |
54 | #include <kglobal.h> | 54 | #include <kglobal.h> |
55 | #include <kconfig.h> | 55 | #include <kconfig.h> |
56 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
57 | 57 | ||
58 | QDateTime KSyncManager::mRequestedSyncEvent; | 58 | QDateTime KSyncManager::mRequestedSyncEvent; |
59 | 59 | ||
60 | 60 | ||
61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
62 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) | 62 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) |
63 | { | 63 | { |
64 | mServerSocket = 0; | 64 | mServerSocket = 0; |
65 | bar = new QProgressBar ( 1, 0 ); | 65 | bar = new QProgressBar ( 1, 0 ); |
66 | bar->setCaption (""); | 66 | bar->setCaption (""); |
67 | 67 | ||
68 | int w = 300; | 68 | int w = 300; |
69 | if ( QApplication::desktop()->width() < 320 ) | 69 | if ( QApplication::desktop()->width() < 320 ) |
70 | w = 220; | 70 | w = 220; |
71 | int h = bar->sizeHint().height() ; | 71 | int h = bar->sizeHint().height() ; |
72 | int dw = QApplication::desktop()->width(); | 72 | int dw = QApplication::desktop()->width(); |
73 | int dh = QApplication::desktop()->height(); | 73 | int dh = QApplication::desktop()->height(); |
74 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 74 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
75 | if ( mPrefs->mPassiveSyncAutoStart ) | 75 | if ( mPrefs->mPassiveSyncAutoStart ) |
76 | enableQuick( false ); | 76 | enableQuick( false ); |
77 | 77 | ||
78 | } | 78 | } |
79 | 79 | ||
80 | KSyncManager::~KSyncManager() | 80 | KSyncManager::~KSyncManager() |
81 | { | 81 | { |
82 | delete bar; | 82 | delete bar; |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | void KSyncManager::fillSyncMenu() | 86 | void KSyncManager::fillSyncMenu() |
87 | { | 87 | { |
88 | if ( mSyncMenu->count() ) | 88 | if ( mSyncMenu->count() ) |
89 | mSyncMenu->clear(); | 89 | mSyncMenu->clear(); |
90 | 90 | ||
91 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 91 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
92 | mSyncMenu->insertSeparator(); | 92 | mSyncMenu->insertSeparator(); |
93 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); | 93 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); |
94 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); | 94 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); |
95 | clearMenu->insertItem( i18n("For all profiles"), 1 ); | 95 | clearMenu->insertItem( i18n("For all profiles"), 1 ); |
96 | clearMenu->insertSeparator(); | 96 | clearMenu->insertSeparator(); |
97 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); | 97 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); |
98 | mSyncMenu->insertSeparator(); | 98 | mSyncMenu->insertSeparator(); |
99 | if ( mServerSocket == 0 ) { | 99 | if ( mServerSocket == 0 ) { |
100 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 100 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
101 | } else { | 101 | } else { |
102 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 102 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
103 | } | 103 | } |
104 | mSyncMenu->insertSeparator(); | 104 | mSyncMenu->insertSeparator(); |
105 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 105 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
106 | mSyncMenu->insertSeparator(); | 106 | mSyncMenu->insertSeparator(); |
107 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 107 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
108 | config.setGroup("General"); | 108 | config.setGroup("General"); |
109 | QStringList prof = config.readListEntry("SyncProfileNames"); | 109 | QStringList prof = config.readListEntry("SyncProfileNames"); |
110 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 110 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
111 | if ( prof.count() < 2 ) { | 111 | if ( prof.count() < 2 ) { |
112 | prof.clear(); | 112 | prof.clear(); |
113 | QString externalName; | 113 | QString externalName; |
114 | #ifdef DESKTOP_VERSION | 114 | #ifdef DESKTOP_VERSION |
115 | #ifdef _WIN32_ | 115 | #ifdef _WIN32_ |
116 | externalName = "OutLook(not_implemented)"; | 116 | externalName = "OutLook(not_implemented)"; |
117 | #else | 117 | #else |
118 | externalName = "KDE_Desktop"; | 118 | externalName = "KDE_Desktop"; |
119 | #endif | 119 | #endif |
120 | #else | 120 | #else |
121 | externalName = "Sharp_DTM"; | 121 | externalName = "Sharp_DTM"; |
122 | #endif | 122 | #endif |
123 | prof << externalName; | 123 | prof << externalName; |
124 | prof << i18n("Local_file"); | 124 | prof << i18n("Local_file"); |
125 | prof << i18n("Last_file"); | 125 | prof << i18n("Last_file"); |
126 | KSyncProfile* temp = new KSyncProfile (); | 126 | KSyncProfile* temp = new KSyncProfile (); |
127 | temp->setName( prof[0] ); | 127 | temp->setName( prof[0] ); |
128 | temp->writeConfig(&config); | 128 | temp->writeConfig(&config); |
129 | temp->setName( prof[1] ); | 129 | temp->setName( prof[1] ); |
130 | temp->writeConfig(&config); | 130 | temp->writeConfig(&config); |
131 | temp->setName( prof[2] ); | 131 | temp->setName( prof[2] ); |
132 | temp->writeConfig(&config); | 132 | temp->writeConfig(&config); |
133 | config.setGroup("General"); | 133 | config.setGroup("General"); |
134 | config.writeEntry("SyncProfileNames",prof); | 134 | config.writeEntry("SyncProfileNames",prof); |
135 | config.writeEntry("ExternSyncProfiles",externalName); | 135 | config.writeEntry("ExternSyncProfiles",externalName); |
136 | config.sync(); | 136 | config.sync(); |
137 | delete temp; | 137 | delete temp; |
138 | } | 138 | } |
139 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 139 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
140 | mSyncProfileNames = prof; | 140 | mSyncProfileNames = prof; |
141 | unsigned int i; | 141 | unsigned int i; |
142 | for ( i = 0; i < prof.count(); ++i ) { | 142 | for ( i = 0; i < prof.count(); ++i ) { |
143 | mSyncMenu->insertItem( prof[i], 1000+i ); | 143 | mSyncMenu->insertItem( prof[i], 1000+i ); |
144 | clearMenu->insertItem( prof[i], 1000+i ); | 144 | clearMenu->insertItem( prof[i], 1000+i ); |
145 | if ( i == 2 ) | 145 | if ( i == 2 ) |
146 | mSyncMenu->insertSeparator(); | 146 | mSyncMenu->insertSeparator(); |
147 | } | 147 | } |
148 | QDir app_dir; | 148 | QDir app_dir; |
149 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 149 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
150 | if ( mTargetApp == PWMPI) { | 150 | if ( mTargetApp == PWMPI) { |
151 | mSyncMenu->removeItem( 1000 ); | 151 | mSyncMenu->removeItem( 1000 ); |
152 | clearMenu->removeItem( 1000 ); | 152 | clearMenu->removeItem( 1000 ); |
153 | } | 153 | } |
154 | #ifndef DESKTOP_VERSION | 154 | #ifndef DESKTOP_VERSION |
155 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 155 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
156 | mSyncMenu->removeItem( 1000 ); | 156 | mSyncMenu->removeItem( 1000 ); |
157 | clearMenu->removeItem( 1000 ); | 157 | clearMenu->removeItem( 1000 ); |
158 | } | 158 | } |
159 | #endif | 159 | #endif |
160 | mSyncMenu->removeItem( 1002 ); | 160 | mSyncMenu->removeItem( 1002 ); |
161 | clearMenu->removeItem( 1002 ); | 161 | clearMenu->removeItem( 1002 ); |
162 | } | 162 | } |
163 | void KSyncManager::slotClearMenu( int action ) | 163 | void KSyncManager::slotClearMenu( int action ) |
164 | { | 164 | { |
165 | QString syncDevice; | 165 | QString syncDevice; |
166 | if ( action > 999 ) { | 166 | if ( action > 999 ) { |
167 | syncDevice = mSyncProfileNames[action - 1000] ; | 167 | syncDevice = mSyncProfileNames[action - 1000] ; |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | 171 | ||
172 | int result = 0; | 172 | int result = 0; |
173 | QString sd; | 173 | QString sd; |
174 | if ( syncDevice.isEmpty() ) | 174 | if ( syncDevice.isEmpty() ) |
175 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); | 175 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); |
176 | else | 176 | else |
177 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); | 177 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); |
178 | 178 | ||
179 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, | 179 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, |
180 | 0, 1 ); | 180 | 0, 1 ); |
181 | if ( result ) | 181 | if ( result ) |
182 | return; | 182 | return; |
183 | mImplementation->removeSyncInfo( syncDevice ); | 183 | mImplementation->removeSyncInfo( syncDevice ); |
184 | } | 184 | } |
185 | void KSyncManager::slotSyncMenu( int action ) | 185 | void KSyncManager::slotSyncMenu( int action ) |
186 | { | 186 | { |
187 | qDebug("syncaction %d ", action); | 187 | qDebug("syncaction %d ", action); |
188 | if ( action == 5000 ) | 188 | if ( action == 5000 ) |
189 | return; | 189 | return; |
190 | mSyncWithDesktop = false; | 190 | mSyncWithDesktop = false; |
191 | if ( action == 0 ) { | 191 | if ( action == 0 ) { |
192 | 192 | ||
193 | // seems to be a Qt2 event handling bug | 193 | // seems to be a Qt2 event handling bug |
194 | // syncmenu.clear causes a segfault at first time | 194 | // syncmenu.clear causes a segfault at first time |
195 | // when we call it after the main event loop, it is ok | 195 | // when we call it after the main event loop, it is ok |
196 | // same behaviour when calling OM/Pi via QCOP for the first time | 196 | // same behaviour when calling OM/Pi via QCOP for the first time |
197 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 197 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
198 | //confSync(); | 198 | //confSync(); |
199 | 199 | ||
200 | return; | 200 | return; |
201 | } | 201 | } |
202 | if ( action == 1 ) { | 202 | if ( action == 1 ) { |
203 | multiSync( true ); | 203 | multiSync( true ); |
204 | return; | 204 | return; |
205 | } | 205 | } |
206 | if ( action == 2 ) { | 206 | if ( action == 2 ) { |
207 | enableQuick(); | 207 | enableQuick(); |
208 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 208 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
209 | return; | 209 | return; |
210 | } | 210 | } |
211 | if ( action == 3 ) { | 211 | if ( action == 3 ) { |
212 | delete mServerSocket; | 212 | delete mServerSocket; |
213 | mServerSocket = 0; | 213 | mServerSocket = 0; |
214 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 214 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
215 | return; | 215 | return; |
216 | } | 216 | } |
217 | 217 | ||
218 | if (blockSave()) | 218 | if (blockSave()) |
219 | return; | 219 | return; |
220 | 220 | ||
221 | setBlockSave(true); | 221 | setBlockSave(true); |
222 | bool silent = false; | 222 | bool silent = false; |
223 | if ( action == 999 ) { | 223 | if ( action == 999 ) { |
224 | //special mode for silent syncing | 224 | //special mode for silent syncing |
225 | action = 1000; | 225 | action = 1000; |
226 | silent = true; | 226 | silent = true; |
227 | } | 227 | } |
228 | 228 | ||
229 | mCurrentSyncProfile = action - 1000 ; | 229 | mCurrentSyncProfile = action - 1000 ; |
230 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 230 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
231 | mCurrentSyncName = mLocalMachineName ; | 231 | mCurrentSyncName = mLocalMachineName ; |
232 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 232 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
233 | KSyncProfile* temp = new KSyncProfile (); | 233 | KSyncProfile* temp = new KSyncProfile (); |
234 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 234 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
235 | temp->readConfig(&config); | 235 | temp->readConfig(&config); |
236 | if (silent) { | 236 | if (silent) { |
237 | mAskForPreferences = false; | 237 | mAskForPreferences = false; |
238 | mShowSyncSummary = false; | 238 | mShowSyncSummary = false; |
239 | mWriteBackFile = true; | 239 | mWriteBackFile = true; |
240 | mSyncAlgoPrefs = 2;// take newest | 240 | mSyncAlgoPrefs = 2;// take newest |
241 | } | 241 | } |
242 | else { | 242 | else { |
243 | mAskForPreferences = temp->getAskForPreferences(); | 243 | mAskForPreferences = temp->getAskForPreferences(); |
244 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 244 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
245 | mWriteBackFile = temp->getWriteBackFile(); | 245 | mWriteBackFile = temp->getWriteBackFile(); |
246 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 246 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
247 | } | 247 | } |
248 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 248 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
249 | mIsKapiFile = temp->getIsKapiFile(); | 249 | mIsKapiFile = temp->getIsKapiFile(); |
250 | mWriteBackInFuture = 0; | 250 | mWriteBackInFuture = 0; |
251 | if ( temp->getWriteBackFuture() ) | 251 | if ( temp->getWriteBackFuture() ) |
252 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 252 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
253 | 253 | ||
254 | if ( action == 1000 ) { | 254 | if ( action == 1000 ) { |
255 | mIsKapiFile = false; | 255 | mIsKapiFile = false; |
256 | #ifdef DESKTOP_VERSION | 256 | #ifdef DESKTOP_VERSION |
257 | syncKDE(); | 257 | syncKDE(); |
258 | #else | 258 | #else |
259 | syncSharp(); | 259 | syncSharp(); |
260 | #endif | 260 | #endif |
261 | 261 | ||
262 | } else if ( action == 1001 ) { | 262 | } else if ( action == 1001 ) { |
263 | syncLocalFile(); | 263 | syncLocalFile(); |
264 | 264 | ||
265 | } else if ( action == 1002 ) { | 265 | } else if ( action == 1002 ) { |
266 | mWriteBackFile = false; | 266 | mWriteBackFile = false; |
267 | mAskForPreferences = false; | 267 | mAskForPreferences = false; |
268 | mShowSyncSummary = false; | 268 | mShowSyncSummary = false; |
269 | mSyncAlgoPrefs = 3; | 269 | mSyncAlgoPrefs = 3; |
270 | quickSyncLocalFile(); | 270 | quickSyncLocalFile(); |
271 | 271 | ||
272 | } else if ( action >= 1003 ) { | 272 | } else if ( action >= 1003 ) { |
273 | if ( temp->getIsLocalFileSync() ) { | 273 | if ( temp->getIsLocalFileSync() ) { |
274 | switch(mTargetApp) | 274 | switch(mTargetApp) |
275 | { | 275 | { |
276 | case (KAPI): | 276 | case (KAPI): |
277 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 277 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
278 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 278 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
279 | break; | 279 | break; |
280 | case (KOPI): | 280 | case (KOPI): |
281 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 281 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
282 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 282 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
283 | break; | 283 | break; |
284 | case (PWMPI): | 284 | case (PWMPI): |
285 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 285 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
286 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 286 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
287 | break; | 287 | break; |
288 | default: | 288 | default: |
289 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 289 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
290 | break; | 290 | break; |
291 | 291 | ||
292 | } | 292 | } |
293 | } else { | 293 | } else { |
294 | if ( temp->getIsPhoneSync() ) { | 294 | if ( temp->getIsPhoneSync() ) { |
295 | mPhoneDevice = temp->getPhoneDevice( ) ; | 295 | mPhoneDevice = temp->getPhoneDevice( ) ; |
296 | mPhoneConnection = temp->getPhoneConnection( ); | 296 | mPhoneConnection = temp->getPhoneConnection( ); |
297 | mPhoneModel = temp->getPhoneModel( ); | 297 | mPhoneModel = temp->getPhoneModel( ); |
298 | syncPhone(); | 298 | syncPhone(); |
299 | } else if ( temp->getIsPiSync() ) { | 299 | } else if ( temp->getIsPiSync() ) { |
300 | if ( mTargetApp == KAPI ) { | 300 | if ( mTargetApp == KAPI ) { |
301 | mPassWordPiSync = temp->getRemotePwAB(); | 301 | mPassWordPiSync = temp->getRemotePwAB(); |
302 | mActiveSyncPort = temp->getRemotePortAB(); | 302 | mActiveSyncPort = temp->getRemotePortAB(); |
303 | mActiveSyncIP = temp->getRemoteIPAB(); | 303 | mActiveSyncIP = temp->getRemoteIPAB(); |
304 | } else if ( mTargetApp == KOPI ) { | 304 | } else if ( mTargetApp == KOPI ) { |
305 | mPassWordPiSync = temp->getRemotePw(); | 305 | mPassWordPiSync = temp->getRemotePw(); |
306 | mActiveSyncPort = temp->getRemotePort(); | 306 | mActiveSyncPort = temp->getRemotePort(); |
307 | mActiveSyncIP = temp->getRemoteIP(); | 307 | mActiveSyncIP = temp->getRemoteIP(); |
308 | } else { | 308 | } else { |
309 | mPassWordPiSync = temp->getRemotePwPWM(); | 309 | mPassWordPiSync = temp->getRemotePwPWM(); |
310 | mActiveSyncPort = temp->getRemotePortPWM(); | 310 | mActiveSyncPort = temp->getRemotePortPWM(); |
311 | mActiveSyncIP = temp->getRemoteIPPWM(); | 311 | mActiveSyncIP = temp->getRemoteIPPWM(); |
312 | } | 312 | } |
313 | syncPi(); | 313 | syncPi(); |
314 | while ( !mPisyncFinished ) { | 314 | while ( !mPisyncFinished ) { |
315 | //qDebug("waiting "); | 315 | //qDebug("waiting "); |
316 | qApp->processEvents(); | 316 | qApp->processEvents(); |
317 | } | 317 | } |
318 | } else | 318 | } else |
319 | syncRemote( temp ); | 319 | syncRemote( temp ); |
320 | 320 | ||
321 | } | 321 | } |
322 | } | 322 | } |
323 | delete temp; | 323 | delete temp; |
324 | setBlockSave(false); | 324 | setBlockSave(false); |
325 | } | 325 | } |
326 | 326 | ||
327 | void KSyncManager::enableQuick( bool ask ) | 327 | void KSyncManager::enableQuick( bool ask ) |
328 | { | 328 | { |
329 | bool autoStart; | 329 | bool autoStart; |
330 | bool changed = false; | 330 | bool changed = false; |
331 | if ( ask ) { | 331 | if ( ask ) { |
332 | QDialog dia ( 0, "input-dialog", true ); | 332 | QDialog dia ( 0, "input-dialog", true ); |
333 | QLineEdit lab ( &dia ); | 333 | QLineEdit lab ( &dia ); |
334 | QVBoxLayout lay( &dia ); | 334 | QVBoxLayout lay( &dia ); |
335 | lab.setText( mPrefs->mPassiveSyncPort ); | 335 | lab.setText( mPrefs->mPassiveSyncPort ); |
336 | lay.setMargin(7); | 336 | lay.setMargin(7); |
337 | lay.setSpacing(7); | 337 | lay.setSpacing(7); |
338 | int po = 9197+mTargetApp; | 338 | int po = 9197+mTargetApp; |
339 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 339 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
340 | lay.addWidget( &label); | 340 | lay.addWidget( &label); |
341 | lay.addWidget( &lab); | 341 | lay.addWidget( &lab); |
342 | 342 | ||
343 | QLineEdit lepw ( &dia ); | 343 | QLineEdit lepw ( &dia ); |
344 | lepw.setText( mPrefs->mPassiveSyncPw ); | 344 | lepw.setText( mPrefs->mPassiveSyncPw ); |
345 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 345 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
346 | lay.addWidget( &label2); | 346 | lay.addWidget( &label2); |
347 | lay.addWidget( &lepw); | 347 | lay.addWidget( &lepw); |
348 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); | 348 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
349 | lay.addWidget( &autostart); | 349 | lay.addWidget( &autostart); |
350 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); | 350 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
351 | #ifdef DESKTOP_VERSION | 351 | #ifdef DESKTOP_VERSION |
352 | #ifdef _WIN32_ | 352 | #ifdef _WIN32_ |
353 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); | 353 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
354 | syncdesktop.hide();// not implemented! | 354 | syncdesktop.hide();// not implemented! |
355 | #else | 355 | #else |
356 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); | 356 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
357 | #endif | 357 | #endif |
358 | lay.addWidget( &syncdesktop); | 358 | lay.addWidget( &syncdesktop); |
359 | #else | 359 | #else |
360 | mPrefs->mPassiveSyncWithDesktop = false; | 360 | mPrefs->mPassiveSyncWithDesktop = false; |
361 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | 361 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); |
362 | syncdesktop.hide(); | 362 | syncdesktop.hide(); |
363 | #endif | 363 | #endif |
364 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | 364 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); |
365 | 365 | ||
366 | dia.setFixedSize( 230,120 ); | 366 | dia.setFixedSize( 230,120 ); |
367 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 367 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
368 | QPushButton pb ( "OK", &dia); | 368 | QPushButton pb ( "OK", &dia); |
369 | lay.addWidget( &pb ); | 369 | lay.addWidget( &pb ); |
370 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 370 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
371 | dia.show(); | 371 | dia.show(); |
372 | if ( ! dia.exec() ) | 372 | if ( ! dia.exec() ) |
373 | return; | 373 | return; |
374 | dia.hide(); | 374 | dia.hide(); |
375 | qApp->processEvents(); | 375 | qApp->processEvents(); |
376 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { | 376 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { |
377 | changed = true; | 377 | changed = true; |
378 | mPrefs->mPassiveSyncPw = lepw.text(); | 378 | mPrefs->mPassiveSyncPw = lepw.text(); |
379 | } | 379 | } |
380 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { | 380 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { |
381 | mPrefs->mPassiveSyncPort = lab.text(); | 381 | mPrefs->mPassiveSyncPort = lab.text(); |
382 | changed = true; | 382 | changed = true; |
383 | } | 383 | } |
384 | autoStart = autostart.isChecked(); | 384 | autoStart = autostart.isChecked(); |
385 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { | 385 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { |
386 | changed = true; | 386 | changed = true; |
387 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | 387 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); |
388 | } | 388 | } |
389 | } | 389 | } |
390 | else | 390 | else |
391 | autoStart = mPrefs->mPassiveSyncAutoStart; | 391 | autoStart = mPrefs->mPassiveSyncAutoStart; |
392 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) | 392 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) |
393 | changed = true; | 393 | changed = true; |
394 | bool ok; | 394 | bool ok; |
395 | mPrefs->mPassiveSyncAutoStart = false; | 395 | mPrefs->mPassiveSyncAutoStart = false; |
396 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 396 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
397 | if ( ! ok ) { | 397 | if ( ! ok ) { |
398 | KMessageBox::information( 0, i18n("No valid port")); | 398 | KMessageBox::information( 0, i18n("No valid port")); |
399 | return; | 399 | return; |
400 | } | 400 | } |
401 | //qDebug("port %d ", port); | 401 | //qDebug("port %d ", port); |
402 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 402 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
403 | mServerSocket->setFileName( defaultFileName() ); | 403 | mServerSocket->setFileName( defaultFileName() );//bbb |
404 | //qDebug("connected "); | 404 | //qDebug("connected "); |
405 | if ( !mServerSocket->ok() ) { | 405 | if ( !mServerSocket->ok() ) { |
406 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 406 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
407 | delete mServerSocket; | 407 | delete mServerSocket; |
408 | mServerSocket = 0; | 408 | mServerSocket = 0; |
409 | return; | 409 | return; |
410 | } | 410 | } |
411 | mPrefs->mPassiveSyncAutoStart = autoStart; | 411 | mPrefs->mPassiveSyncAutoStart = autoStart; |
412 | if ( changed ) { | 412 | if ( changed ) { |
413 | mPrefs->writeConfig(); | 413 | mPrefs->writeConfig(); |
414 | } | 414 | } |
415 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 415 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
416 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 416 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
417 | } | 417 | } |
418 | 418 | ||
419 | void KSyncManager::syncLocalFile() | 419 | void KSyncManager::syncLocalFile() |
420 | { | 420 | { |
421 | 421 | ||
422 | QString fn =mPrefs->mLastSyncedLocalFile; | 422 | QString fn =mPrefs->mLastSyncedLocalFile; |
423 | QString ext; | 423 | QString ext; |
424 | 424 | ||
425 | switch(mTargetApp) | 425 | switch(mTargetApp) |
426 | { | 426 | { |
427 | case (KAPI): | 427 | case (KAPI): |
428 | ext = "(*.vcf)"; | 428 | ext = "(*.vcf)"; |
429 | break; | 429 | break; |
430 | case (KOPI): | 430 | case (KOPI): |
431 | ext = "(*.ics/*.vcs)"; | 431 | ext = "(*.ics/*.vcs)"; |
432 | break; | 432 | break; |
433 | case (PWMPI): | 433 | case (PWMPI): |
434 | ext = "(*.pwm)"; | 434 | ext = "(*.pwm)"; |
435 | break; | 435 | break; |
436 | default: | 436 | default: |
437 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 437 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
438 | break; | 438 | break; |
439 | 439 | ||
440 | } | 440 | } |
441 | 441 | ||
442 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 442 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
443 | if ( fn == "" ) | 443 | if ( fn == "" ) |
444 | return; | 444 | return; |
445 | if ( syncWithFile( fn, false ) ) { | 445 | if ( syncWithFile( fn, false ) ) { |
446 | qDebug("syncLocalFile() successful "); | 446 | qDebug("syncLocalFile() successful "); |
447 | } | 447 | } |
448 | 448 | ||
449 | } | 449 | } |
450 | 450 | ||
451 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 451 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
452 | { | 452 | { |
453 | bool ret = false; | 453 | bool ret = false; |
454 | QFileInfo info; | 454 | QFileInfo info; |
455 | info.setFile( fn ); | 455 | info.setFile( fn ); |
456 | QString mess; | 456 | QString mess; |
457 | bool loadbup = true; | 457 | bool loadbup = true; |
458 | if ( !info. exists() ) { | 458 | if ( !info. exists() ) { |
459 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 459 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
460 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 460 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
461 | mess ); | 461 | mess ); |
462 | return ret; | 462 | return ret; |
463 | } | 463 | } |
464 | int result = 0; | 464 | int result = 0; |
465 | if ( !quick ) { | 465 | if ( !quick ) { |
466 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 466 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
467 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 467 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
468 | mess, | 468 | mess, |
469 | i18n("Sync"), i18n("Cancel"), 0, | 469 | i18n("Sync"), i18n("Cancel"), 0, |
470 | 0, 1 ); | 470 | 0, 1 ); |
471 | if ( result ) | 471 | if ( result ) |
472 | return false; | 472 | return false; |
473 | } | 473 | } |
474 | if ( mAskForPreferences ) | 474 | if ( mAskForPreferences ) |
475 | if ( !edit_sync_options()) { | 475 | if ( !edit_sync_options()) { |
476 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 476 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
477 | return false; | 477 | return false; |
478 | } | 478 | } |
479 | if ( result == 0 ) { | 479 | if ( result == 0 ) { |
480 | //qDebug("Now sycing ... "); | 480 | //qDebug("Now sycing ... "); |
481 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 481 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
482 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); | 482 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
483 | else | 483 | else |
484 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); | 484 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); |
485 | if ( ! quick ) | 485 | if ( ! quick ) |
486 | mPrefs->mLastSyncedLocalFile = fn; | 486 | mPrefs->mLastSyncedLocalFile = fn; |
487 | } | 487 | } |
488 | return ret; | 488 | return ret; |
489 | } | 489 | } |
490 | 490 | ||
491 | void KSyncManager::quickSyncLocalFile() | 491 | void KSyncManager::quickSyncLocalFile() |
492 | { | 492 | { |
493 | 493 | ||
494 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { | 494 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { |
495 | qDebug("quick syncLocalFile() successful "); | 495 | qDebug("quick syncLocalFile() successful "); |
496 | 496 | ||
497 | } | 497 | } |
498 | } | 498 | } |
499 | 499 | ||
500 | void KSyncManager::multiSync( bool askforPrefs ) | 500 | void KSyncManager::multiSync( bool askforPrefs ) |
501 | { | 501 | { |
502 | if (blockSave()) | 502 | if (blockSave()) |
503 | return; | 503 | return; |
504 | setBlockSave(true); | 504 | setBlockSave(true); |
505 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 505 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
506 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), | 506 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), |
507 | question, | 507 | question, |
508 | i18n("Yes"), i18n("No"), | 508 | i18n("Yes"), i18n("No"), |
509 | 0, 0 ) != 0 ) { | 509 | 0, 0 ) != 0 ) { |
510 | setBlockSave(false); | 510 | setBlockSave(false); |
511 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); | 511 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
512 | return; | 512 | return; |
513 | } | 513 | } |
514 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 514 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
515 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; | 515 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; |
516 | if ( askforPrefs ) { | 516 | if ( askforPrefs ) { |
517 | if ( !edit_sync_options()) { | 517 | if ( !edit_sync_options()) { |
518 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); | 518 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); |
519 | return; | 519 | return; |
520 | } | 520 | } |
521 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 521 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
522 | } | 522 | } |
523 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); | 523 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
524 | qApp->processEvents(); | 524 | qApp->processEvents(); |
525 | int num = ringSync() ; | 525 | int num = ringSync() ; |
526 | if ( num > 1 ) | 526 | if ( num > 1 ) |
527 | ringSync(); | 527 | ringSync(); |
528 | setBlockSave(false); | 528 | setBlockSave(false); |
529 | if ( num ) | 529 | if ( num ) |
530 | emit save(); | 530 | emit save(); |
531 | if ( num ) | 531 | if ( num ) |
532 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 532 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
533 | else | 533 | else |
534 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 534 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
535 | return; | 535 | return; |
536 | } | 536 | } |
537 | 537 | ||
538 | int KSyncManager::ringSync() | 538 | int KSyncManager::ringSync() |
539 | { | 539 | { |
540 | 540 | ||
541 | int syncedProfiles = 0; | 541 | int syncedProfiles = 0; |
542 | unsigned int i; | 542 | unsigned int i; |
543 | QTime timer; | 543 | QTime timer; |
544 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 544 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
545 | QStringList syncProfileNames = mSyncProfileNames; | 545 | QStringList syncProfileNames = mSyncProfileNames; |
546 | KSyncProfile* temp = new KSyncProfile (); | 546 | KSyncProfile* temp = new KSyncProfile (); |
547 | mAskForPreferences = false; | 547 | mAskForPreferences = false; |
548 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 548 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
549 | mCurrentSyncProfile = i; | 549 | mCurrentSyncProfile = i; |
550 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 550 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
551 | temp->readConfig(&config); | 551 | temp->readConfig(&config); |
552 | 552 | ||
553 | bool includeInRingSync; | 553 | bool includeInRingSync; |
554 | switch(mTargetApp) | 554 | switch(mTargetApp) |
555 | { | 555 | { |
556 | case (KAPI): | 556 | case (KAPI): |
557 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 557 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
558 | break; | 558 | break; |
559 | case (KOPI): | 559 | case (KOPI): |
560 | includeInRingSync = temp->getIncludeInRingSync(); | 560 | includeInRingSync = temp->getIncludeInRingSync(); |
561 | break; | 561 | break; |
562 | case (PWMPI): | 562 | case (PWMPI): |
563 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 563 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
564 | break; | 564 | break; |
565 | default: | 565 | default: |
566 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | 566 | qDebug("KSyncManager::ringSync: invalid apptype selected"); |
567 | break; | 567 | break; |
568 | 568 | ||
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 572 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
573 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 573 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
574 | ++syncedProfiles; | 574 | ++syncedProfiles; |
575 | mSyncWithDesktop = false; | 575 | mSyncWithDesktop = false; |
576 | // mAskForPreferences = temp->getAskForPreferences(); | 576 | // mAskForPreferences = temp->getAskForPreferences(); |
577 | mWriteBackFile = temp->getWriteBackFile(); | 577 | mWriteBackFile = temp->getWriteBackFile(); |
578 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 578 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
579 | mIsKapiFile = temp->getIsKapiFile(); | 579 | mIsKapiFile = temp->getIsKapiFile(); |
580 | mWriteBackInFuture = 0; | 580 | mWriteBackInFuture = 0; |
581 | if ( temp->getWriteBackFuture() ) | 581 | if ( temp->getWriteBackFuture() ) |
582 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 582 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
583 | mShowSyncSummary = false; | 583 | mShowSyncSummary = false; |
584 | mCurrentSyncDevice = syncProfileNames[i] ; | 584 | mCurrentSyncDevice = syncProfileNames[i] ; |
585 | mCurrentSyncName = mLocalMachineName; | 585 | mCurrentSyncName = mLocalMachineName; |
586 | if ( i == 0 ) { | 586 | if ( i == 0 ) { |
587 | mIsKapiFile = false; | 587 | mIsKapiFile = false; |
588 | #ifdef DESKTOP_VERSION | 588 | #ifdef DESKTOP_VERSION |
589 | syncKDE(); | 589 | syncKDE(); |
590 | #else | 590 | #else |
591 | syncSharp(); | 591 | syncSharp(); |
592 | #endif | 592 | #endif |
593 | } else { | 593 | } else { |
594 | if ( temp->getIsLocalFileSync() ) { | 594 | if ( temp->getIsLocalFileSync() ) { |
595 | switch(mTargetApp) | 595 | switch(mTargetApp) |
596 | { | 596 | { |
597 | case (KAPI): | 597 | case (KAPI): |
598 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 598 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
599 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 599 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
600 | break; | 600 | break; |
601 | case (KOPI): | 601 | case (KOPI): |
602 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 602 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
603 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 603 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
604 | break; | 604 | break; |
605 | case (PWMPI): | 605 | case (PWMPI): |
606 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 606 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
607 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 607 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
608 | break; | 608 | break; |
609 | default: | 609 | default: |
610 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 610 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
611 | break; | 611 | break; |
612 | } | 612 | } |
613 | } else { | 613 | } else { |
614 | if ( temp->getIsPhoneSync() ) { | 614 | if ( temp->getIsPhoneSync() ) { |
615 | mPhoneDevice = temp->getPhoneDevice( ) ; | 615 | mPhoneDevice = temp->getPhoneDevice( ) ; |
616 | mPhoneConnection = temp->getPhoneConnection( ); | 616 | mPhoneConnection = temp->getPhoneConnection( ); |
617 | mPhoneModel = temp->getPhoneModel( ); | 617 | mPhoneModel = temp->getPhoneModel( ); |
618 | syncPhone(); | 618 | syncPhone(); |
619 | } else if ( temp->getIsPiSync() ) { | 619 | } else if ( temp->getIsPiSync() ) { |
620 | if ( mTargetApp == KAPI ) { | 620 | if ( mTargetApp == KAPI ) { |
621 | mPassWordPiSync = temp->getRemotePwAB(); | 621 | mPassWordPiSync = temp->getRemotePwAB(); |
622 | mActiveSyncPort = temp->getRemotePortAB(); | 622 | mActiveSyncPort = temp->getRemotePortAB(); |
623 | mActiveSyncIP = temp->getRemoteIPAB(); | 623 | mActiveSyncIP = temp->getRemoteIPAB(); |
624 | } else if ( mTargetApp == KOPI ) { | 624 | } else if ( mTargetApp == KOPI ) { |
625 | mPassWordPiSync = temp->getRemotePw(); | 625 | mPassWordPiSync = temp->getRemotePw(); |
626 | mActiveSyncPort = temp->getRemotePort(); | 626 | mActiveSyncPort = temp->getRemotePort(); |
627 | mActiveSyncIP = temp->getRemoteIP(); | 627 | mActiveSyncIP = temp->getRemoteIP(); |
628 | } else { | 628 | } else { |
629 | mPassWordPiSync = temp->getRemotePwPWM(); | 629 | mPassWordPiSync = temp->getRemotePwPWM(); |
630 | mActiveSyncPort = temp->getRemotePortPWM(); | 630 | mActiveSyncPort = temp->getRemotePortPWM(); |
631 | mActiveSyncIP = temp->getRemoteIPPWM(); | 631 | mActiveSyncIP = temp->getRemoteIPPWM(); |
632 | } | 632 | } |
633 | syncPi(); | 633 | syncPi(); |
634 | while ( !mPisyncFinished ) { | 634 | while ( !mPisyncFinished ) { |
635 | //qDebug("waiting "); | 635 | //qDebug("waiting "); |
636 | qApp->processEvents(); | 636 | qApp->processEvents(); |
637 | } | 637 | } |
638 | timer.start(); | 638 | timer.start(); |
639 | while ( timer.elapsed () < 2000 ) { | 639 | while ( timer.elapsed () < 2000 ) { |
640 | qApp->processEvents(); | 640 | qApp->processEvents(); |
641 | } | 641 | } |
642 | } else | 642 | } else |
643 | syncRemote( temp, false ); | 643 | syncRemote( temp, false ); |
644 | 644 | ||
645 | } | 645 | } |
646 | } | 646 | } |
647 | timer.start(); | 647 | timer.start(); |
648 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 648 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
649 | while ( timer.elapsed () < 2000 ) { | 649 | while ( timer.elapsed () < 2000 ) { |
650 | qApp->processEvents(); | 650 | qApp->processEvents(); |
651 | #ifndef _WIN32_ | 651 | #ifndef _WIN32_ |
652 | sleep (1); | 652 | sleep (1); |
653 | #endif | 653 | #endif |
654 | } | 654 | } |
655 | 655 | ||
656 | } | 656 | } |
657 | 657 | ||
658 | } | 658 | } |
659 | delete temp; | 659 | delete temp; |
660 | return syncedProfiles; | 660 | return syncedProfiles; |
661 | } | 661 | } |
662 | 662 | ||
663 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 663 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
664 | { | 664 | { |
665 | QString question; | 665 | QString question; |
666 | if ( ask ) { | 666 | if ( ask ) { |
667 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 667 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
668 | if ( QMessageBox::information( mParent, i18n("Sync"), | 668 | if ( QMessageBox::information( mParent, i18n("Sync"), |
669 | question, | 669 | question, |
670 | i18n("Yes"), i18n("No"), | 670 | i18n("Yes"), i18n("No"), |
671 | 0, 0 ) != 0 ) | 671 | 0, 0 ) != 0 ) |
672 | return; | 672 | return; |
673 | } | 673 | } |
674 | 674 | ||
675 | QString preCommand; | 675 | QString preCommand; |
676 | QString localTempFile; | 676 | QString localTempFile; |
677 | QString postCommand; | 677 | QString postCommand; |
678 | 678 | ||
679 | switch(mTargetApp) | 679 | switch(mTargetApp) |
680 | { | 680 | { |
681 | case (KAPI): | 681 | case (KAPI): |
682 | preCommand = prof->getPreSyncCommandAB(); | 682 | preCommand = prof->getPreSyncCommandAB(); |
683 | postCommand = prof->getPostSyncCommandAB(); | 683 | postCommand = prof->getPostSyncCommandAB(); |
684 | localTempFile = prof->getLocalTempFileAB(); | 684 | localTempFile = prof->getLocalTempFileAB(); |
685 | break; | 685 | break; |
686 | case (KOPI): | 686 | case (KOPI): |
687 | preCommand = prof->getPreSyncCommand(); | 687 | preCommand = prof->getPreSyncCommand(); |
688 | postCommand = prof->getPostSyncCommand(); | 688 | postCommand = prof->getPostSyncCommand(); |
689 | localTempFile = prof->getLocalTempFile(); | 689 | localTempFile = prof->getLocalTempFile(); |
690 | break; | 690 | break; |
691 | case (PWMPI): | 691 | case (PWMPI): |
692 | preCommand = prof->getPreSyncCommandPWM(); | 692 | preCommand = prof->getPreSyncCommandPWM(); |
693 | postCommand = prof->getPostSyncCommandPWM(); | 693 | postCommand = prof->getPostSyncCommandPWM(); |
694 | localTempFile = prof->getLocalTempFilePWM(); | 694 | localTempFile = prof->getLocalTempFilePWM(); |
695 | break; | 695 | break; |
696 | default: | 696 | default: |
697 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); | 697 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); |
698 | break; | 698 | break; |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | int fi; | 702 | int fi; |
703 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 703 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
704 | QString pwd = getPassword(); | 704 | QString pwd = getPassword(); |
705 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 705 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
706 | 706 | ||
707 | } | 707 | } |
708 | int maxlen = 30; | 708 | int maxlen = 30; |
709 | if ( QApplication::desktop()->width() > 320 ) | 709 | if ( QApplication::desktop()->width() > 320 ) |
710 | maxlen += 25; | 710 | maxlen += 25; |
711 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 711 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
712 | int fileSize = 0; | 712 | int fileSize = 0; |
713 | int result = system ( preCommand ); | 713 | int result = system ( preCommand ); |
714 | // 0 : okay | 714 | // 0 : okay |
715 | // 256: no such file or dir | 715 | // 256: no such file or dir |
716 | // | 716 | // |
717 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); | 717 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); |
718 | if ( result != 0 ) { | 718 | if ( result != 0 ) { |
719 | unsigned int len = maxlen; | 719 | unsigned int len = maxlen; |
720 | while ( len < preCommand.length() ) { | 720 | while ( len < preCommand.length() ) { |
721 | preCommand.insert( len , "\n" ); | 721 | preCommand.insert( len , "\n" ); |
722 | len += maxlen +2; | 722 | len += maxlen +2; |
723 | } | 723 | } |
724 | 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) ; | 724 | 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) ; |
725 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 725 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
726 | question, | 726 | question, |
727 | i18n("Okay!")) ; | 727 | i18n("Okay!")) ; |
728 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); | 728 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); |
729 | return; | 729 | return; |
730 | } | 730 | } |
731 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 731 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
732 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 732 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
733 | 733 | ||
734 | if ( syncWithFile( localTempFile, true ) ) { | 734 | if ( syncWithFile( localTempFile, true ) ) { |
735 | 735 | ||
736 | if ( mWriteBackFile ) { | 736 | if ( mWriteBackFile ) { |
737 | int fi; | 737 | int fi; |
738 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 738 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
739 | QString pwd = getPassword(); | 739 | QString pwd = getPassword(); |
740 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 740 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
741 | 741 | ||
742 | } | 742 | } |
743 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 743 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
744 | result = system ( postCommand ); | 744 | result = system ( postCommand ); |
745 | qDebug("Sync:Writing back file result: %d ", result); | 745 | qDebug("Sync:Writing back file result: %d ", result); |
746 | if ( result != 0 ) { | 746 | if ( result != 0 ) { |
747 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 747 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
748 | return; | 748 | return; |
749 | } else { | 749 | } else { |
750 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 750 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
751 | } | 751 | } |
752 | } | 752 | } |
753 | } | 753 | } |
754 | return; | 754 | return; |
755 | } | 755 | } |
756 | bool KSyncManager::edit_pisync_options() | 756 | bool KSyncManager::edit_pisync_options() |
757 | { | 757 | { |
758 | QDialog dia( mParent, "dia", true ); | 758 | QDialog dia( mParent, "dia", true ); |
759 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 759 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
760 | QVBoxLayout lay ( &dia ); | 760 | QVBoxLayout lay ( &dia ); |
761 | lay.setSpacing( 5 ); | 761 | lay.setSpacing( 5 ); |
762 | lay.setMargin( 3 ); | 762 | lay.setMargin( 3 ); |
763 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 763 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
764 | lay.addWidget( &lab1 ); | 764 | lay.addWidget( &lab1 ); |
765 | QLineEdit le1 (&dia ); | 765 | QLineEdit le1 (&dia ); |
766 | lay.addWidget( &le1 ); | 766 | lay.addWidget( &le1 ); |
767 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 767 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
768 | lay.addWidget( &lab2 ); | 768 | lay.addWidget( &lab2 ); |
769 | QLineEdit le2 (&dia ); | 769 | QLineEdit le2 (&dia ); |
770 | lay.addWidget( &le2 ); | 770 | lay.addWidget( &le2 ); |
771 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 771 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
772 | lay.addWidget( &lab3 ); | 772 | lay.addWidget( &lab3 ); |
773 | QLineEdit le3 (&dia ); | 773 | QLineEdit le3 (&dia ); |
774 | lay.addWidget( &le3 ); | 774 | lay.addWidget( &le3 ); |
775 | QPushButton pb ( "OK", &dia); | 775 | QPushButton pb ( "OK", &dia); |
776 | lay.addWidget( &pb ); | 776 | lay.addWidget( &pb ); |
777 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 777 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
778 | le1.setText( mPassWordPiSync ); | 778 | le1.setText( mPassWordPiSync ); |
779 | le2.setText( mActiveSyncIP ); | 779 | le2.setText( mActiveSyncIP ); |
780 | le3.setText( mActiveSyncPort ); | 780 | le3.setText( mActiveSyncPort ); |
781 | if ( dia.exec() ) { | 781 | if ( dia.exec() ) { |
782 | mPassWordPiSync = le1.text(); | 782 | mPassWordPiSync = le1.text(); |
783 | mActiveSyncPort = le3.text(); | 783 | mActiveSyncPort = le3.text(); |
784 | mActiveSyncIP = le2.text(); | 784 | mActiveSyncIP = le2.text(); |
785 | return true; | 785 | return true; |
786 | } | 786 | } |
787 | return false; | 787 | return false; |
@@ -856,617 +856,617 @@ QString KSyncManager::getPassword( ) | |||
856 | dia.show(); | 856 | dia.show(); |
857 | int res = dia.exec(); | 857 | int res = dia.exec(); |
858 | if ( res ) | 858 | if ( res ) |
859 | retfile = lab.text(); | 859 | retfile = lab.text(); |
860 | dia.hide(); | 860 | dia.hide(); |
861 | qApp->processEvents(); | 861 | qApp->processEvents(); |
862 | return retfile; | 862 | return retfile; |
863 | 863 | ||
864 | } | 864 | } |
865 | 865 | ||
866 | 866 | ||
867 | void KSyncManager::confSync() | 867 | void KSyncManager::confSync() |
868 | { | 868 | { |
869 | static KSyncPrefsDialog* sp = 0; | 869 | static KSyncPrefsDialog* sp = 0; |
870 | if ( ! sp ) { | 870 | if ( ! sp ) { |
871 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 871 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
872 | } | 872 | } |
873 | sp->usrReadConfig(); | 873 | sp->usrReadConfig(); |
874 | #ifndef DESKTOP_VERSION | 874 | #ifndef DESKTOP_VERSION |
875 | sp->showMaximized(); | 875 | sp->showMaximized(); |
876 | #else | 876 | #else |
877 | sp->show(); | 877 | sp->show(); |
878 | #endif | 878 | #endif |
879 | sp->exec(); | 879 | sp->exec(); |
880 | QStringList oldSyncProfileNames = mSyncProfileNames; | 880 | QStringList oldSyncProfileNames = mSyncProfileNames; |
881 | mSyncProfileNames = sp->getSyncProfileNames(); | 881 | mSyncProfileNames = sp->getSyncProfileNames(); |
882 | mLocalMachineName = sp->getLocalMachineName (); | 882 | mLocalMachineName = sp->getLocalMachineName (); |
883 | int ii; | 883 | int ii; |
884 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { | 884 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { |
885 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) | 885 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) |
886 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); | 886 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); |
887 | } | 887 | } |
888 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 888 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
889 | } | 889 | } |
890 | void KSyncManager::syncKDE() | 890 | void KSyncManager::syncKDE() |
891 | { | 891 | { |
892 | mSyncWithDesktop = true; | 892 | mSyncWithDesktop = true; |
893 | emit save(); | 893 | emit save(); |
894 | switch(mTargetApp) | 894 | switch(mTargetApp) |
895 | { | 895 | { |
896 | case (KAPI): | 896 | case (KAPI): |
897 | { | 897 | { |
898 | #ifdef DESKTOP_VERSION | 898 | #ifdef DESKTOP_VERSION |
899 | QString command = qApp->applicationDirPath () + "/kdeabdump"; | 899 | QString command = qApp->applicationDirPath () + "/kdeabdump"; |
900 | #else | 900 | #else |
901 | QString command = "kdeabdump"; | 901 | QString command = "kdeabdump"; |
902 | #endif | 902 | #endif |
903 | if ( ! QFile::exists ( command ) ) | 903 | if ( ! QFile::exists ( command ) ) |
904 | command = "kdeabdump"; | 904 | command = "kdeabdump"; |
905 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 905 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
906 | system ( command.latin1()); | 906 | system ( command.latin1()); |
907 | if ( syncWithFile( fileName,true ) ) { | 907 | if ( syncWithFile( fileName,true ) ) { |
908 | if ( mWriteBackFile ) { | 908 | if ( mWriteBackFile ) { |
909 | command += " --read"; | 909 | command += " --read"; |
910 | system ( command.latin1()); | 910 | system ( command.latin1()); |
911 | } | 911 | } |
912 | } | 912 | } |
913 | 913 | ||
914 | } | 914 | } |
915 | break; | 915 | break; |
916 | case (KOPI): | 916 | case (KOPI): |
917 | { | 917 | { |
918 | #ifdef DESKTOP_VERSION | 918 | #ifdef DESKTOP_VERSION |
919 | QString command = qApp->applicationDirPath () + "/kdecaldump"; | 919 | QString command = qApp->applicationDirPath () + "/kdecaldump"; |
920 | #else | 920 | #else |
921 | QString command = "kdecaldump"; | 921 | QString command = "kdecaldump"; |
922 | #endif | 922 | #endif |
923 | if ( ! QFile::exists ( command ) ) | 923 | if ( ! QFile::exists ( command ) ) |
924 | command = "kdecaldump"; | 924 | command = "kdecaldump"; |
925 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 925 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
926 | system ( command.latin1()); | 926 | system ( command.latin1()); |
927 | if ( syncWithFile( fileName,true ) ) { | 927 | if ( syncWithFile( fileName,true ) ) { |
928 | if ( mWriteBackFile ) { | 928 | if ( mWriteBackFile ) { |
929 | command += " --read"; | 929 | command += " --read"; |
930 | system ( command.latin1()); | 930 | system ( command.latin1()); |
931 | } | 931 | } |
932 | } | 932 | } |
933 | 933 | ||
934 | } | 934 | } |
935 | break; | 935 | break; |
936 | case (PWMPI): | 936 | case (PWMPI): |
937 | 937 | ||
938 | break; | 938 | break; |
939 | default: | 939 | default: |
940 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 940 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
941 | break; | 941 | break; |
942 | 942 | ||
943 | } | 943 | } |
944 | } | 944 | } |
945 | 945 | ||
946 | void KSyncManager::syncSharp() | 946 | void KSyncManager::syncSharp() |
947 | { | 947 | { |
948 | 948 | ||
949 | if ( ! syncExternalApplication("sharp") ) | 949 | if ( ! syncExternalApplication("sharp") ) |
950 | qDebug("ERROR sync sharp "); | 950 | qDebug("ERROR sync sharp "); |
951 | } | 951 | } |
952 | 952 | ||
953 | bool KSyncManager::syncExternalApplication(QString resource) | 953 | bool KSyncManager::syncExternalApplication(QString resource) |
954 | { | 954 | { |
955 | 955 | ||
956 | emit save(); | 956 | emit save(); |
957 | 957 | ||
958 | if ( mAskForPreferences ) | 958 | if ( mAskForPreferences ) |
959 | if ( !edit_sync_options()) { | 959 | if ( !edit_sync_options()) { |
960 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 960 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
961 | return false; | 961 | return false; |
962 | } | 962 | } |
963 | 963 | ||
964 | qDebug("Sync extern %s", resource.latin1()); | 964 | qDebug("Sync extern %s", resource.latin1()); |
965 | 965 | ||
966 | bool syncOK = mImplementation->syncExternal(this, resource); | 966 | bool syncOK = mImplementation->syncExternal(this, resource); |
967 | 967 | ||
968 | return syncOK; | 968 | return syncOK; |
969 | 969 | ||
970 | } | 970 | } |
971 | 971 | ||
972 | void KSyncManager::syncPhone() | 972 | void KSyncManager::syncPhone() |
973 | { | 973 | { |
974 | 974 | ||
975 | syncExternalApplication("phone"); | 975 | syncExternalApplication("phone"); |
976 | 976 | ||
977 | } | 977 | } |
978 | 978 | ||
979 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 979 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
980 | { | 980 | { |
981 | if (!bar->isVisible()) | 981 | if (!bar->isVisible()) |
982 | { | 982 | { |
983 | bar->setCaption (caption); | 983 | bar->setCaption (caption); |
984 | bar->setTotalSteps ( total ) ; | 984 | bar->setTotalSteps ( total ) ; |
985 | 985 | ||
986 | bar->show(); | 986 | bar->show(); |
987 | } | 987 | } |
988 | 988 | ||
989 | bar->setProgress( percentage ); | 989 | bar->setProgress( percentage ); |
990 | } | 990 | } |
991 | 991 | ||
992 | void KSyncManager::hideProgressBar() | 992 | void KSyncManager::hideProgressBar() |
993 | { | 993 | { |
994 | bar->hide(); | 994 | bar->hide(); |
995 | } | 995 | } |
996 | 996 | ||
997 | bool KSyncManager::isProgressBarCanceled() | 997 | bool KSyncManager::isProgressBarCanceled() |
998 | { | 998 | { |
999 | return !bar->isVisible(); | 999 | return !bar->isVisible(); |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | QString KSyncManager::syncFileName() | 1002 | QString KSyncManager::syncFileName() |
1003 | { | 1003 | { |
1004 | 1004 | ||
1005 | QString fn = "tempfile"; | 1005 | QString fn = "tempfile"; |
1006 | switch(mTargetApp) | 1006 | switch(mTargetApp) |
1007 | { | 1007 | { |
1008 | case (KAPI): | 1008 | case (KAPI): |
1009 | fn = "tempsyncab.vcf"; | 1009 | fn = "tempsyncab.vcf"; |
1010 | break; | 1010 | break; |
1011 | case (KOPI): | 1011 | case (KOPI): |
1012 | fn = "tempsynccal.ics"; | 1012 | fn = "tempsynccal.ics"; |
1013 | break; | 1013 | break; |
1014 | case (PWMPI): | 1014 | case (PWMPI): |
1015 | fn = "tempsyncpw.pwm"; | 1015 | fn = "tempsyncpw.pwm"; |
1016 | break; | 1016 | break; |
1017 | default: | 1017 | default: |
1018 | break; | 1018 | break; |
1019 | } | 1019 | } |
1020 | #ifdef _WIN32_ | 1020 | #ifdef _WIN32_ |
1021 | return locateLocal( "tmp", fn ); | 1021 | return locateLocal( "tmp", fn ); |
1022 | #else | 1022 | #else |
1023 | return (QString( "/tmp/" )+ fn ); | 1023 | return (QString( "/tmp/" )+ fn ); |
1024 | #endif | 1024 | #endif |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | void KSyncManager::syncPi() | 1027 | void KSyncManager::syncPi() |
1028 | { | 1028 | { |
1029 | mIsKapiFile = true; | 1029 | mIsKapiFile = true; |
1030 | mPisyncFinished = false; | 1030 | mPisyncFinished = false; |
1031 | qApp->processEvents(); | 1031 | qApp->processEvents(); |
1032 | if ( mAskForPreferences ) | 1032 | if ( mAskForPreferences ) |
1033 | if ( !edit_pisync_options()) { | 1033 | if ( !edit_pisync_options()) { |
1034 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1034 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1035 | return; | 1035 | return; |
1036 | } | 1036 | } |
1037 | bool ok; | 1037 | bool ok; |
1038 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1038 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1039 | if ( ! ok ) { | 1039 | if ( ! ok ) { |
1040 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1040 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1041 | return; | 1041 | return; |
1042 | } | 1042 | } |
1043 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 1043 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); |
1044 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1044 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1045 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); | 1045 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); |
1046 | commandSocket->readFile( syncFileName() ); | 1046 | commandSocket->readFile( syncFileName() ); |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1049 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1050 | { | 1050 | { |
1051 | //enum { success, errorW, errorR, quiet }; | 1051 | //enum { success, errorW, errorR, quiet }; |
1052 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { | 1052 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { |
1053 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1053 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1054 | delete s; | 1054 | delete s; |
1055 | if ( state == KCommandSocket::errorR ) { | 1055 | if ( state == KCommandSocket::errorR ) { |
1056 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1056 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
1057 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1057 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1058 | commandSocket->sendStop(); | 1058 | commandSocket->sendStop(); |
1059 | } | 1059 | } |
1060 | mPisyncFinished = true; | 1060 | mPisyncFinished = true; |
1061 | return; | 1061 | return; |
1062 | 1062 | ||
1063 | } else if ( state == KCommandSocket::errorW ) { | 1063 | } else if ( state == KCommandSocket::errorW ) { |
1064 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1064 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1065 | mPisyncFinished = true; | 1065 | mPisyncFinished = true; |
1066 | 1066 | ||
1067 | } else if ( state == KCommandSocket::successR ) { | 1067 | } else if ( state == KCommandSocket::successR ) { |
1068 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1068 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1069 | 1069 | ||
1070 | } else if ( state == KCommandSocket::successW ) { | 1070 | } else if ( state == KCommandSocket::successW ) { |
1071 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1071 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1072 | mPisyncFinished = true; | 1072 | mPisyncFinished = true; |
1073 | } | 1073 | } |
1074 | 1074 | ||
1075 | delete s; | 1075 | delete s; |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | void KSyncManager::readFileFromSocket() | 1078 | void KSyncManager::readFileFromSocket() |
1079 | { | 1079 | { |
1080 | QString fileName = syncFileName(); | 1080 | QString fileName = syncFileName(); |
1081 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1081 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1082 | if ( ! syncWithFile( fileName , true ) ) { | 1082 | if ( ! syncWithFile( fileName , true ) ) { |
1083 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1083 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1084 | mPisyncFinished = true; | 1084 | mPisyncFinished = true; |
1085 | return; | 1085 | return; |
1086 | } | 1086 | } |
1087 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1087 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
1088 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1088 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1089 | if ( mWriteBackFile ) | 1089 | if ( mWriteBackFile ) |
1090 | commandSocket->writeFile( fileName ); | 1090 | commandSocket->writeFile( fileName ); |
1091 | else { | 1091 | else { |
1092 | commandSocket->sendStop(); | 1092 | commandSocket->sendStop(); |
1093 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1093 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1094 | mPisyncFinished = true; | 1094 | mPisyncFinished = true; |
1095 | } | 1095 | } |
1096 | } | 1096 | } |
1097 | 1097 | ||
1098 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1098 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1099 | { | 1099 | { |
1100 | mPassWord = pw; | 1100 | mPassWord = pw; |
1101 | mSocket = 0; | 1101 | mSocket = 0; |
1102 | mSyncActionDialog = 0; | 1102 | mSyncActionDialog = 0; |
1103 | blockRC = false; | 1103 | blockRC = false; |
1104 | }; | 1104 | }; |
1105 | 1105 | ||
1106 | void KServerSocket::newConnection ( int socket ) | 1106 | void KServerSocket::newConnection ( int socket ) |
1107 | { | 1107 | { |
1108 | // qDebug("KServerSocket:New connection %d ", socket); | 1108 | // qDebug("KServerSocket:New connection %d ", socket); |
1109 | if ( mSocket ) { | 1109 | if ( mSocket ) { |
1110 | qDebug("KServerSocket::newConnection Socket deleted! "); | 1110 | qDebug("KServerSocket::newConnection Socket deleted! "); |
1111 | delete mSocket; | 1111 | delete mSocket; |
1112 | mSocket = 0; | 1112 | mSocket = 0; |
1113 | } | 1113 | } |
1114 | mSocket = new QSocket( this ); | 1114 | mSocket = new QSocket( this ); |
1115 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1115 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1116 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1116 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1117 | mSocket->setSocket( socket ); | 1117 | mSocket->setSocket( socket ); |
1118 | } | 1118 | } |
1119 | 1119 | ||
1120 | void KServerSocket::discardClient() | 1120 | void KServerSocket::discardClient() |
1121 | { | 1121 | { |
1122 | //qDebug(" KServerSocket::discardClient()"); | 1122 | //qDebug(" KServerSocket::discardClient()"); |
1123 | if ( mSocket ) { | 1123 | if ( mSocket ) { |
1124 | delete mSocket; | 1124 | delete mSocket; |
1125 | mSocket = 0; | 1125 | mSocket = 0; |
1126 | } | 1126 | } |
1127 | //emit endConnect(); | 1127 | //emit endConnect(); |
1128 | } | 1128 | } |
1129 | void KServerSocket::readClient() | 1129 | void KServerSocket::readClient() |
1130 | { | 1130 | { |
1131 | if ( blockRC ) | 1131 | if ( blockRC ) |
1132 | return; | 1132 | return; |
1133 | if ( mSocket == 0 ) { | 1133 | if ( mSocket == 0 ) { |
1134 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 1134 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
1135 | return; | 1135 | return; |
1136 | } | 1136 | } |
1137 | //qDebug("KServerSocket::readClient()"); | 1137 | //qDebug("KServerSocket::readClient()"); |
1138 | if ( mSocket->canReadLine() ) { | 1138 | if ( mSocket->canReadLine() ) { |
1139 | QString line = mSocket->readLine(); | 1139 | QString line = mSocket->readLine(); |
1140 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1140 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1141 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1141 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1142 | if ( tokens[0] == "GET" ) { | 1142 | if ( tokens[0] == "GET" ) { |
1143 | if ( tokens[1] == mPassWord ) { | 1143 | if ( tokens[1] == mPassWord ) { |
1144 | //emit sendFile( mSocket ); | 1144 | //emit sendFile( mSocket ); |
1145 | bool ok = false; | 1145 | bool ok = false; |
1146 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1146 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1147 | if ( ok ) { | 1147 | if ( ok ) { |
1148 | KSyncManager::mRequestedSyncEvent = dt; | 1148 | KSyncManager::mRequestedSyncEvent = dt; |
1149 | } | 1149 | } |
1150 | else | 1150 | else |
1151 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1151 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1152 | send_file(); | 1152 | send_file(); |
1153 | } | 1153 | } |
1154 | else { | 1154 | else { |
1155 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1155 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1156 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1156 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1157 | } | 1157 | } |
1158 | } | 1158 | } |
1159 | if ( tokens[0] == "PUT" ) { | 1159 | if ( tokens[0] == "PUT" ) { |
1160 | if ( tokens[1] == mPassWord ) { | 1160 | if ( tokens[1] == mPassWord ) { |
1161 | //emit getFile( mSocket ); | 1161 | //emit getFile( mSocket ); |
1162 | blockRC = true; | 1162 | blockRC = true; |
1163 | get_file(); | 1163 | get_file(); |
1164 | } | 1164 | } |
1165 | else { | 1165 | else { |
1166 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1166 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1167 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1167 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1168 | } | 1168 | } |
1169 | } | 1169 | } |
1170 | if ( tokens[0] == "STOP" ) { | 1170 | if ( tokens[0] == "STOP" ) { |
1171 | //emit endConnect(); | 1171 | //emit endConnect(); |
1172 | end_connect(); | 1172 | end_connect(); |
1173 | } | 1173 | } |
1174 | } | 1174 | } |
1175 | } | 1175 | } |
1176 | void KServerSocket::end_connect() | 1176 | void KServerSocket::end_connect() |
1177 | { | 1177 | { |
1178 | delete mSyncActionDialog; | 1178 | delete mSyncActionDialog; |
1179 | mSyncActionDialog = 0; | 1179 | mSyncActionDialog = 0; |
1180 | } | 1180 | } |
1181 | void KServerSocket::send_file() | 1181 | void KServerSocket::send_file() |
1182 | { | 1182 | { |
1183 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1183 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1184 | if ( mSyncActionDialog ) | 1184 | if ( mSyncActionDialog ) |
1185 | delete mSyncActionDialog; | 1185 | delete mSyncActionDialog; |
1186 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1186 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1187 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1187 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1188 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1188 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1189 | label->setAlignment ( Qt::AlignHCenter ); | 1189 | label->setAlignment ( Qt::AlignHCenter ); |
1190 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1190 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1191 | lay->addWidget( label); | 1191 | lay->addWidget( label); |
1192 | lay->setMargin(7); | 1192 | lay->setMargin(7); |
1193 | lay->setSpacing(7); | 1193 | lay->setSpacing(7); |
1194 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1194 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1195 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); | 1195 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); |
1196 | if ( secs < 0 ) | 1196 | if ( secs < 0 ) |
1197 | secs = secs * (-1); | 1197 | secs = secs * (-1); |
1198 | if ( secs > 30 ) | 1198 | if ( secs > 30 ) |
1199 | //if ( true ) | 1199 | //if ( true ) |
1200 | { | 1200 | { |
1201 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); | 1201 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); |
1202 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1202 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1203 | label->setAlignment ( Qt::AlignHCenter ); | 1203 | label->setAlignment ( Qt::AlignHCenter ); |
1204 | lay->addWidget( label); | 1204 | lay->addWidget( label); |
1205 | if ( secs > 180 ) | 1205 | if ( secs > 180 ) |
1206 | { | 1206 | { |
1207 | if ( secs > 300 ) { | 1207 | if ( secs > 300 ) { |
1208 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { | 1208 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { |
1209 | qDebug("cancelled "); | 1209 | qDebug("cancelled "); |
1210 | return ; | 1210 | return ; |
1211 | } | 1211 | } |
1212 | } | 1212 | } |
1213 | QFont f = label->font(); | 1213 | QFont f = label->font(); |
1214 | f.setPointSize ( f.pointSize() *2 ); | 1214 | f.setPointSize ( f.pointSize() *2 ); |
1215 | f. setBold (true ); | 1215 | f. setBold (true ); |
1216 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1216 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1217 | label->setFont( f ); | 1217 | label->setFont( f ); |
1218 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); | 1218 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); |
1219 | label->setText( warning ); | 1219 | label->setText( warning ); |
1220 | label->setAlignment ( Qt::AlignHCenter ); | 1220 | label->setAlignment ( Qt::AlignHCenter ); |
1221 | lay->addWidget( label); | 1221 | lay->addWidget( label); |
1222 | mSyncActionDialog->setFixedSize( 230, 300); | 1222 | mSyncActionDialog->setFixedSize( 230, 300); |
1223 | } else { | 1223 | } else { |
1224 | mSyncActionDialog->setFixedSize( 230, 200); | 1224 | mSyncActionDialog->setFixedSize( 230, 200); |
1225 | } | 1225 | } |
1226 | } else { | 1226 | } else { |
1227 | mSyncActionDialog->setFixedSize( 230, 120); | 1227 | mSyncActionDialog->setFixedSize( 230, 120); |
1228 | } | 1228 | } |
1229 | } else | 1229 | } else |
1230 | mSyncActionDialog->setFixedSize( 230, 120); | 1230 | mSyncActionDialog->setFixedSize( 230, 120); |
1231 | mSyncActionDialog->show(); | 1231 | mSyncActionDialog->show(); |
1232 | mSyncActionDialog->raise(); | 1232 | mSyncActionDialog->raise(); |
1233 | emit request_file(); | 1233 | emit request_file(); |
1234 | qApp->processEvents(); | 1234 | qApp->processEvents(); |
1235 | QString fileName = mFileName; | 1235 | QString fileName = mFileName; |
1236 | QFile file( fileName ); | 1236 | QFile file( fileName ); |
1237 | if (!file.open( IO_ReadOnly ) ) { | 1237 | if (!file.open( IO_ReadOnly ) ) { |
1238 | delete mSyncActionDialog; | 1238 | delete mSyncActionDialog; |
1239 | mSyncActionDialog = 0; | 1239 | mSyncActionDialog = 0; |
1240 | qDebug("KSS::error open file "); | 1240 | qDebug("KSS::error open sync file: %s ", fileName.latin1()); |
1241 | mSocket->close(); | 1241 | mSocket->close(); |
1242 | if ( mSocket->state() == QSocket::Idle ) | 1242 | if ( mSocket->state() == QSocket::Idle ) |
1243 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1243 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1244 | return ; | 1244 | return ; |
1245 | 1245 | ||
1246 | } | 1246 | } |
1247 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1247 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1248 | QTextStream ts( &file ); | 1248 | QTextStream ts( &file ); |
1249 | ts.setEncoding( QTextStream::Latin1 ); | 1249 | ts.setEncoding( QTextStream::Latin1 ); |
1250 | 1250 | ||
1251 | QTextStream os( mSocket ); | 1251 | QTextStream os( mSocket ); |
1252 | os.setEncoding( QTextStream::Latin1 ); | 1252 | os.setEncoding( QTextStream::Latin1 ); |
1253 | while ( ! ts.atEnd() ) { | 1253 | while ( ! ts.atEnd() ) { |
1254 | os << ts.readLine() << "\r\n"; | 1254 | os << ts.readLine() << "\r\n"; |
1255 | } | 1255 | } |
1256 | //os << ts.read(); | 1256 | //os << ts.read(); |
1257 | file.close(); | 1257 | file.close(); |
1258 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1258 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1259 | mSocket->close(); | 1259 | mSocket->close(); |
1260 | if ( mSocket->state() == QSocket::Idle ) | 1260 | if ( mSocket->state() == QSocket::Idle ) |
1261 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1261 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1262 | } | 1262 | } |
1263 | void KServerSocket::get_file() | 1263 | void KServerSocket::get_file() |
1264 | { | 1264 | { |
1265 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1265 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1266 | 1266 | ||
1267 | piTime.start(); | 1267 | piTime.start(); |
1268 | piFileString = ""; | 1268 | piFileString = ""; |
1269 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1269 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1270 | } | 1270 | } |
1271 | 1271 | ||
1272 | 1272 | ||
1273 | void KServerSocket::readBackFileFromSocket() | 1273 | void KServerSocket::readBackFileFromSocket() |
1274 | { | 1274 | { |
1275 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1275 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1276 | while ( mSocket->canReadLine () ) { | 1276 | while ( mSocket->canReadLine () ) { |
1277 | piTime.restart(); | 1277 | piTime.restart(); |
1278 | QString line = mSocket->readLine (); | 1278 | QString line = mSocket->readLine (); |
1279 | piFileString += line; | 1279 | piFileString += line; |
1280 | //qDebug("readline: %s ", line.latin1()); | 1280 | //qDebug("readline: %s ", line.latin1()); |
1281 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1281 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1282 | 1282 | ||
1283 | } | 1283 | } |
1284 | if ( piTime.elapsed () < 3000 ) { | 1284 | if ( piTime.elapsed () < 3000 ) { |
1285 | // wait for more | 1285 | // wait for more |
1286 | //qDebug("waitformore "); | 1286 | //qDebug("waitformore "); |
1287 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1287 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1288 | return; | 1288 | return; |
1289 | } | 1289 | } |
1290 | QString fileName = mFileName; | 1290 | QString fileName = mFileName; |
1291 | QFile file ( fileName ); | 1291 | QFile file ( fileName ); |
1292 | if (!file.open( IO_WriteOnly ) ) { | 1292 | if (!file.open( IO_WriteOnly ) ) { |
1293 | delete mSyncActionDialog; | 1293 | delete mSyncActionDialog; |
1294 | mSyncActionDialog = 0; | 1294 | mSyncActionDialog = 0; |
1295 | qDebug("KSS:Error open read back file "); | 1295 | qDebug("KSS:Error open read back file "); |
1296 | piFileString = ""; | 1296 | piFileString = ""; |
1297 | emit file_received( false ); | 1297 | emit file_received( false ); |
1298 | blockRC = false; | 1298 | blockRC = false; |
1299 | return ; | 1299 | return ; |
1300 | 1300 | ||
1301 | } | 1301 | } |
1302 | 1302 | ||
1303 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1303 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1304 | QTextStream ts ( &file ); | 1304 | QTextStream ts ( &file ); |
1305 | ts.setEncoding( QTextStream::Latin1 ); | 1305 | ts.setEncoding( QTextStream::Latin1 ); |
1306 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1306 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1307 | ts << piFileString; | 1307 | ts << piFileString; |
1308 | mSocket->close(); | 1308 | mSocket->close(); |
1309 | if ( mSocket->state() == QSocket::Idle ) | 1309 | if ( mSocket->state() == QSocket::Idle ) |
1310 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1310 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1311 | file.close(); | 1311 | file.close(); |
1312 | piFileString = ""; | 1312 | piFileString = ""; |
1313 | emit file_received( true ); | 1313 | emit file_received( true ); |
1314 | delete mSyncActionDialog; | 1314 | delete mSyncActionDialog; |
1315 | mSyncActionDialog = 0; | 1315 | mSyncActionDialog = 0; |
1316 | blockRC = false; | 1316 | blockRC = false; |
1317 | 1317 | ||
1318 | } | 1318 | } |
1319 | 1319 | ||
1320 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1320 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1321 | { | 1321 | { |
1322 | mPassWord = password; | 1322 | mPassWord = password; |
1323 | mSocket = 0; | 1323 | mSocket = 0; |
1324 | mPort = port; | 1324 | mPort = port; |
1325 | mHost = host; | 1325 | mHost = host; |
1326 | 1326 | ||
1327 | mRetVal = quiet; | 1327 | mRetVal = quiet; |
1328 | mTimerSocket = new QTimer ( this ); | 1328 | mTimerSocket = new QTimer ( this ); |
1329 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1329 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1330 | } | 1330 | } |
1331 | void KCommandSocket::readFile( QString fn ) | 1331 | void KCommandSocket::readFile( QString fn ) |
1332 | { | 1332 | { |
1333 | if ( !mSocket ) { | 1333 | if ( !mSocket ) { |
1334 | mSocket = new QSocket( this ); | 1334 | mSocket = new QSocket( this ); |
1335 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1335 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1336 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1336 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1337 | } | 1337 | } |
1338 | mFileString = ""; | 1338 | mFileString = ""; |
1339 | mFileName = fn; | 1339 | mFileName = fn; |
1340 | mFirst = true; | 1340 | mFirst = true; |
1341 | mSocket->connectToHost( mHost, mPort ); | 1341 | mSocket->connectToHost( mHost, mPort ); |
1342 | QTextStream os( mSocket ); | 1342 | QTextStream os( mSocket ); |
1343 | os.setEncoding( QTextStream::Latin1 ); | 1343 | os.setEncoding( QTextStream::Latin1 ); |
1344 | 1344 | ||
1345 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | 1345 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); |
1346 | os << "GET " << mPassWord << curDt <<"\r\n"; | 1346 | os << "GET " << mPassWord << curDt <<"\r\n"; |
1347 | mTimerSocket->start( 20000 ); | 1347 | mTimerSocket->start( 20000 ); |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | void KCommandSocket::writeFile( QString fileName ) | 1350 | void KCommandSocket::writeFile( QString fileName ) |
1351 | { | 1351 | { |
1352 | if ( !mSocket ) { | 1352 | if ( !mSocket ) { |
1353 | mSocket = new QSocket( this ); | 1353 | mSocket = new QSocket( this ); |
1354 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1354 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1355 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1355 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1356 | } | 1356 | } |
1357 | mFileName = fileName ; | 1357 | mFileName = fileName ; |
1358 | mSocket->connectToHost( mHost, mPort ); | 1358 | mSocket->connectToHost( mHost, mPort ); |
1359 | } | 1359 | } |
1360 | void KCommandSocket::writeFileToSocket() | 1360 | void KCommandSocket::writeFileToSocket() |
1361 | { | 1361 | { |
1362 | QFile file2( mFileName ); | 1362 | QFile file2( mFileName ); |
1363 | if (!file2.open( IO_ReadOnly ) ) { | 1363 | if (!file2.open( IO_ReadOnly ) ) { |
1364 | mRetVal= errorW; | 1364 | mRetVal= errorW; |
1365 | mSocket->close(); | 1365 | mSocket->close(); |
1366 | if ( mSocket->state() == QSocket::Idle ) | 1366 | if ( mSocket->state() == QSocket::Idle ) |
1367 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1367 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1368 | return ; | 1368 | return ; |
1369 | } | 1369 | } |
1370 | QTextStream ts2( &file2 ); | 1370 | QTextStream ts2( &file2 ); |
1371 | ts2.setEncoding( QTextStream::Latin1 ); | 1371 | ts2.setEncoding( QTextStream::Latin1 ); |
1372 | QTextStream os2( mSocket ); | 1372 | QTextStream os2( mSocket ); |
1373 | os2.setEncoding( QTextStream::Latin1 ); | 1373 | os2.setEncoding( QTextStream::Latin1 ); |
1374 | os2 << "PUT " << mPassWord << "\r\n";; | 1374 | os2 << "PUT " << mPassWord << "\r\n";; |
1375 | while ( ! ts2.atEnd() ) { | 1375 | while ( ! ts2.atEnd() ) { |
1376 | os2 << ts2.readLine() << "\r\n"; | 1376 | os2 << ts2.readLine() << "\r\n"; |
1377 | } | 1377 | } |
1378 | mRetVal= successW; | 1378 | mRetVal= successW; |
1379 | file2.close(); | 1379 | file2.close(); |
1380 | mSocket->close(); | 1380 | mSocket->close(); |
1381 | if ( mSocket->state() == QSocket::Idle ) | 1381 | if ( mSocket->state() == QSocket::Idle ) |
1382 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1382 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1383 | } | 1383 | } |
1384 | void KCommandSocket::sendStop() | 1384 | void KCommandSocket::sendStop() |
1385 | { | 1385 | { |
1386 | if ( !mSocket ) { | 1386 | if ( !mSocket ) { |
1387 | mSocket = new QSocket( this ); | 1387 | mSocket = new QSocket( this ); |
1388 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1388 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1389 | } | 1389 | } |
1390 | mSocket->connectToHost( mHost, mPort ); | 1390 | mSocket->connectToHost( mHost, mPort ); |
1391 | QTextStream os2( mSocket ); | 1391 | QTextStream os2( mSocket ); |
1392 | os2.setEncoding( QTextStream::Latin1 ); | 1392 | os2.setEncoding( QTextStream::Latin1 ); |
1393 | os2 << "STOP\r\n"; | 1393 | os2 << "STOP\r\n"; |
1394 | mSocket->close(); | 1394 | mSocket->close(); |
1395 | if ( mSocket->state() == QSocket::Idle ) | 1395 | if ( mSocket->state() == QSocket::Idle ) |
1396 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1396 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1397 | } | 1397 | } |
1398 | 1398 | ||
1399 | void KCommandSocket::startReadFileFromSocket() | 1399 | void KCommandSocket::startReadFileFromSocket() |
1400 | { | 1400 | { |
1401 | if ( ! mFirst ) | 1401 | if ( ! mFirst ) |
1402 | return; | 1402 | return; |
1403 | mFirst = false; | 1403 | mFirst = false; |
1404 | mTimerSocket->stop(); | 1404 | mTimerSocket->stop(); |
1405 | mFileString = ""; | 1405 | mFileString = ""; |
1406 | mTime.start(); | 1406 | mTime.start(); |
1407 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1407 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1408 | 1408 | ||
1409 | } | 1409 | } |
1410 | void KCommandSocket::readFileFromSocket() | 1410 | void KCommandSocket::readFileFromSocket() |
1411 | { | 1411 | { |
1412 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1412 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1413 | while ( mSocket->canReadLine () ) { | 1413 | while ( mSocket->canReadLine () ) { |
1414 | mTime.restart(); | 1414 | mTime.restart(); |
1415 | QString line = mSocket->readLine (); | 1415 | QString line = mSocket->readLine (); |
1416 | mFileString += line; | 1416 | mFileString += line; |
1417 | //qDebug("readline: %s ", line.latin1()); | 1417 | //qDebug("readline: %s ", line.latin1()); |
1418 | } | 1418 | } |
1419 | if ( mTime.elapsed () < 3000 ) { | 1419 | if ( mTime.elapsed () < 3000 ) { |
1420 | // wait for more | 1420 | // wait for more |
1421 | //qDebug("waitformore "); | 1421 | //qDebug("waitformore "); |
1422 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1422 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1423 | return; | 1423 | return; |
1424 | } | 1424 | } |
1425 | QString fileName = mFileName; | 1425 | QString fileName = mFileName; |
1426 | QFile file ( fileName ); | 1426 | QFile file ( fileName ); |
1427 | if (!file.open( IO_WriteOnly ) ) { | 1427 | if (!file.open( IO_WriteOnly ) ) { |
1428 | mFileString = ""; | 1428 | mFileString = ""; |
1429 | mRetVal = errorR; | 1429 | mRetVal = errorR; |
1430 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1430 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1431 | deleteSocket(); | 1431 | deleteSocket(); |
1432 | return ; | 1432 | return ; |
1433 | 1433 | ||
1434 | } | 1434 | } |
1435 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1435 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1436 | QTextStream ts ( &file ); | 1436 | QTextStream ts ( &file ); |
1437 | ts.setEncoding( QTextStream::Latin1 ); | 1437 | ts.setEncoding( QTextStream::Latin1 ); |
1438 | ts << mFileString; | 1438 | ts << mFileString; |
1439 | file.close(); | 1439 | file.close(); |
1440 | mFileString = ""; | 1440 | mFileString = ""; |
1441 | mRetVal = successR; | 1441 | mRetVal = successR; |
1442 | mSocket->close(); | 1442 | mSocket->close(); |
1443 | // if state is not idle, deleteSocket(); is called via | 1443 | // if state is not idle, deleteSocket(); is called via |
1444 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1444 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1445 | if ( mSocket->state() == QSocket::Idle ) | 1445 | if ( mSocket->state() == QSocket::Idle ) |
1446 | deleteSocket(); | 1446 | deleteSocket(); |
1447 | } | 1447 | } |
1448 | 1448 | ||
1449 | void KCommandSocket::deleteSocket() | 1449 | void KCommandSocket::deleteSocket() |
1450 | { | 1450 | { |
1451 | //qDebug("KCommandSocket::deleteSocket() "); | 1451 | //qDebug("KCommandSocket::deleteSocket() "); |
1452 | if ( mTimerSocket->isActive () ) { | 1452 | if ( mTimerSocket->isActive () ) { |
1453 | mTimerSocket->stop(); | 1453 | mTimerSocket->stop(); |
1454 | mRetVal = errorTO; | 1454 | mRetVal = errorTO; |
1455 | qDebug("Connection to remote host timed out"); | 1455 | qDebug("Connection to remote host timed out"); |
1456 | if ( mSocket ) { | 1456 | if ( mSocket ) { |
1457 | mSocket->close(); | 1457 | mSocket->close(); |
1458 | //if ( mSocket->state() == QSocket::Idle ) | 1458 | //if ( mSocket->state() == QSocket::Idle ) |
1459 | // deleteSocket(); | 1459 | // deleteSocket(); |
1460 | delete mSocket; | 1460 | delete mSocket; |
1461 | mSocket = 0; | 1461 | mSocket = 0; |
1462 | } | 1462 | } |
1463 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 1463 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); |
1464 | emit commandFinished( this, mRetVal ); | 1464 | emit commandFinished( this, mRetVal ); |
1465 | return; | 1465 | return; |
1466 | } | 1466 | } |
1467 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1467 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1468 | if ( mSocket) | 1468 | if ( mSocket) |
1469 | delete mSocket; | 1469 | delete mSocket; |
1470 | mSocket = 0; | 1470 | mSocket = 0; |
1471 | emit commandFinished( this, mRetVal ); | 1471 | emit commandFinished( this, mRetVal ); |
1472 | } | 1472 | } |