summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp133
-rw-r--r--korganizer/mainwindow.h17
2 files changed, 140 insertions, 10 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index e4b7869..da73caf 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1420,1229 +1420,1348 @@ void MainWindow::slotModifiedChanged( bool changed )
1420 if ( !mBlockSaveFlag ) 1420 if ( !mBlockSaveFlag )
1421 msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000; 1421 msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000;
1422 else 1422 else
1423 msec = 1000 * 600; 1423 msec = 1000 * 600;
1424 mSaveTimer.start( msec, true ); // 1 minute 1424 mSaveTimer.start( msec, true ); // 1 minute
1425 qDebug("KO: Saving File in %d secs!", msec/1000); 1425 qDebug("KO: Saving File in %d secs!", msec/1000);
1426 mCalendarModifiedFlag = true; 1426 mCalendarModifiedFlag = true;
1427} 1427}
1428void MainWindow::save() 1428void MainWindow::save()
1429{ 1429{
1430 if ( mBlockSaveFlag ) 1430 if ( mBlockSaveFlag )
1431 return; 1431 return;
1432 bool store = mBlockSaveFlag; 1432 bool store = mBlockSaveFlag;
1433 mBlockSaveFlag = true; 1433 mBlockSaveFlag = true;
1434 if ( mView->checkFileVersion( defaultFileName()) ) { 1434 if ( mView->checkFileVersion( defaultFileName()) ) {
1435 1435
1436 QTime neededSaveTime = QDateTime::currentDateTime().time(); 1436 QTime neededSaveTime = QDateTime::currentDateTime().time();
1437 setCaption(i18n("KO/Pi:Saving Data to File ..." )); 1437 setCaption(i18n("KO/Pi:Saving Data to File ..." ));
1438 qDebug("KO: Start saving data to file!"); 1438 qDebug("KO: Start saving data to file!");
1439 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1439 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1440 mView->saveCalendar( defaultFileName() ); 1440 mView->saveCalendar( defaultFileName() );
1441 1441
1442 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); 1442 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() );
1443 mView->watchSavedFile(); 1443 mView->watchSavedFile();
1444 qDebug("KO: Needed %d ms for saving.",msNeeded ); 1444 qDebug("KO: Needed %d ms for saving.",msNeeded );
1445 QString savemes; 1445 QString savemes;
1446 savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 ); 1446 savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 );
1447 setCaption(savemes); 1447 setCaption(savemes);
1448 } else 1448 } else
1449 setCaption(i18n("Saving cancelled!")); 1449 setCaption(i18n("Saving cancelled!"));
1450 mCalendarModifiedFlag = false; 1450 mCalendarModifiedFlag = false;
1451 mBlockSaveFlag = store; 1451 mBlockSaveFlag = store;
1452} 1452}
1453 1453
1454void MainWindow::keyReleaseEvent ( QKeyEvent * e) 1454void MainWindow::keyReleaseEvent ( QKeyEvent * e)
1455{ 1455{
1456 if ( !e->isAutoRepeat() ) { 1456 if ( !e->isAutoRepeat() ) {
1457 mFlagKeyPressed = false; 1457 mFlagKeyPressed = false;
1458 } 1458 }
1459} 1459}
1460void MainWindow::keyPressEvent ( QKeyEvent * e ) 1460void MainWindow::keyPressEvent ( QKeyEvent * e )
1461{ 1461{
1462 qApp->processEvents(); 1462 qApp->processEvents();
1463 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 1463 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
1464 e->ignore(); 1464 e->ignore();
1465 // qDebug(" ignore %d",e->isAutoRepeat() ); 1465 // qDebug(" ignore %d",e->isAutoRepeat() );
1466 return; 1466 return;
1467 } 1467 }
1468 if (! e->isAutoRepeat() ) 1468 if (! e->isAutoRepeat() )
1469 mFlagKeyPressed = true; 1469 mFlagKeyPressed = true;
1470 KOPrefs *p = KOPrefs::instance(); 1470 KOPrefs *p = KOPrefs::instance();
1471 bool showSelectedDates = false; 1471 bool showSelectedDates = false;
1472 int size; 1472 int size;
1473 int pro = 0; 1473 int pro = 0;
1474 //qDebug("MainWindow::keyPressEvent "); 1474 //qDebug("MainWindow::keyPressEvent ");
1475 switch ( e->key() ) { 1475 switch ( e->key() ) {
1476 case Qt::Key_Right: 1476 case Qt::Key_Right:
1477 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton) 1477 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton)
1478 mView->goNextMonth(); 1478 mView->goNextMonth();
1479 else 1479 else
1480 mView->goNext(); 1480 mView->goNext();
1481 showSelectedDates = true; 1481 showSelectedDates = true;
1482 break; 1482 break;
1483 case Qt::Key_Left: 1483 case Qt::Key_Left:
1484 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 1484 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
1485 mView->goPreviousMonth(); 1485 mView->goPreviousMonth();
1486 else 1486 else
1487 mView->goPrevious(); 1487 mView->goPrevious();
1488 showSelectedDates = true; 1488 showSelectedDates = true;
1489 break; 1489 break;
1490 case Qt::Key_Down: 1490 case Qt::Key_Down:
1491 mView->viewManager()->agendaView()->scrollOneHourDown(); 1491 mView->viewManager()->agendaView()->scrollOneHourDown();
1492 break; 1492 break;
1493 case Qt::Key_Up: 1493 case Qt::Key_Up:
1494 mView->viewManager()->agendaView()->scrollOneHourUp(); 1494 mView->viewManager()->agendaView()->scrollOneHourUp();
1495 break; 1495 break;
1496 case Qt::Key_I: 1496 case Qt::Key_I:
1497 mView->showIncidence(); 1497 mView->showIncidence();
1498 break; 1498 break;
1499 case Qt::Key_Delete: 1499 case Qt::Key_Delete:
1500 case Qt::Key_Backspace: 1500 case Qt::Key_Backspace:
1501 mView->deleteIncidence(); 1501 mView->deleteIncidence();
1502 break; 1502 break;
1503 case Qt::Key_D: 1503 case Qt::Key_D:
1504 mView->viewManager()->showDayView(); 1504 mView->viewManager()->showDayView();
1505 showSelectedDates = true; 1505 showSelectedDates = true;
1506 break; 1506 break;
1507 case Qt::Key_O: 1507 case Qt::Key_O:
1508 mView->toggleFilerEnabled( ); 1508 mView->toggleFilerEnabled( );
1509 break; 1509 break;
1510 case Qt::Key_0: 1510 case Qt::Key_0:
1511 case Qt::Key_1: 1511 case Qt::Key_1:
1512 case Qt::Key_2: 1512 case Qt::Key_2:
1513 case Qt::Key_3: 1513 case Qt::Key_3:
1514 case Qt::Key_4: 1514 case Qt::Key_4:
1515 case Qt::Key_5: 1515 case Qt::Key_5:
1516 case Qt::Key_6: 1516 case Qt::Key_6:
1517 case Qt::Key_7: 1517 case Qt::Key_7:
1518 case Qt::Key_8: 1518 case Qt::Key_8:
1519 case Qt::Key_9: 1519 case Qt::Key_9:
1520 pro = e->key()-48; 1520 pro = e->key()-48;
1521 if ( pro == 0 ) 1521 if ( pro == 0 )
1522 pro = 10; 1522 pro = 10;
1523 if ( e->state() == Qt::ControlButton) 1523 if ( e->state() == Qt::ControlButton)
1524 pro += 10; 1524 pro += 10;
1525 break; 1525 break;
1526 case Qt::Key_M: 1526 case Qt::Key_M:
1527 mView->viewManager()->showMonthView(); 1527 mView->viewManager()->showMonthView();
1528 showSelectedDates = true; 1528 showSelectedDates = true;
1529 break; 1529 break;
1530 case Qt::Key_Insert: 1530 case Qt::Key_Insert:
1531 mView->newEvent(); 1531 mView->newEvent();
1532 break; 1532 break;
1533 case Qt::Key_S : 1533 case Qt::Key_S :
1534 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton) 1534 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton)
1535 mView->newSubTodo(); 1535 mView->newSubTodo();
1536 else 1536 else
1537 mView->dialogManager()->showSearchDialog(); 1537 mView->dialogManager()->showSearchDialog();
1538 break; 1538 break;
1539 case Qt::Key_Y : 1539 case Qt::Key_Y :
1540 case Qt::Key_Z : 1540 case Qt::Key_Z :
1541 mView->viewManager()->showWorkWeekView(); 1541 mView->viewManager()->showWorkWeekView();
1542 showSelectedDates = true; 1542 showSelectedDates = true;
1543 break; 1543 break;
1544 case Qt::Key_U : 1544 case Qt::Key_U :
1545 mView->viewManager()->showWeekView(); 1545 mView->viewManager()->showWeekView();
1546 showSelectedDates = true; 1546 showSelectedDates = true;
1547 break; 1547 break;
1548 case Qt::Key_H : 1548 case Qt::Key_H :
1549 keyBindings(); 1549 keyBindings();
1550 break; 1550 break;
1551 case Qt::Key_W: 1551 case Qt::Key_W:
1552 mView->viewManager()->showWhatsNextView(); 1552 mView->viewManager()->showWhatsNextView();
1553 break; 1553 break;
1554 case Qt::Key_L: 1554 case Qt::Key_L:
1555 mView->viewManager()->showListView(); 1555 mView->viewManager()->showListView();
1556 break; 1556 break;
1557 case Qt::Key_N: 1557 case Qt::Key_N:
1558 mView->viewManager()->showNextXView(); 1558 mView->viewManager()->showNextXView();
1559 showSelectedDates = true; 1559 showSelectedDates = true;
1560 break; 1560 break;
1561 case Qt::Key_V: 1561 case Qt::Key_V:
1562 mView->viewManager()->showTodoView(); 1562 mView->viewManager()->showTodoView();
1563 break; 1563 break;
1564 case Qt::Key_C: 1564 case Qt::Key_C:
1565 mView->viewManager()->agendaView()->setStartHour( QTime::currentTime ().hour() ); 1565 mView->viewManager()->agendaView()->setStartHour( QTime::currentTime ().hour() );
1566 break; 1566 break;
1567 case Qt::Key_P: 1567 case Qt::Key_P:
1568 mView->showDatePicker( ); 1568 mView->showDatePicker( );
1569 break; 1569 break;
1570 case Qt::Key_F: 1570 case Qt::Key_F:
1571 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 1571 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
1572 mView->editFilters(); 1572 mView->editFilters();
1573 else 1573 else
1574 mView->toggleFilter(); 1574 mView->toggleFilter();
1575 break; 1575 break;
1576 case Qt::Key_X: 1576 case Qt::Key_X:
1577 mView->toggleDateNavigatorWidget(); 1577 mView->toggleDateNavigatorWidget();
1578 break; 1578 break;
1579 case Qt::Key_Space: 1579 case Qt::Key_Space:
1580 mView->toggleExpand(); 1580 mView->toggleExpand();
1581 break; 1581 break;
1582 case Qt::Key_A: 1582 case Qt::Key_A:
1583 mView->toggleAllDaySize(); 1583 mView->toggleAllDaySize();
1584 break; 1584 break;
1585 case Qt::Key_T: 1585 case Qt::Key_T:
1586 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 1586 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
1587 mView->newTodo(); 1587 mView->newTodo();
1588 else { 1588 else {
1589 mView->goToday(); 1589 mView->goToday();
1590 showSelectedDates = true; 1590 showSelectedDates = true;
1591 } 1591 }
1592 break; 1592 break;
1593 case Qt::Key_J: 1593 case Qt::Key_J:
1594 mView->viewManager()->showJournalView(); 1594 mView->viewManager()->showJournalView();
1595 break; 1595 break;
1596 case Qt::Key_B: 1596 case Qt::Key_B:
1597 mView->editIncidenceDescription();; 1597 mView->editIncidenceDescription();;
1598 break; 1598 break;
1599 // case Qt::Key_Return: 1599 // case Qt::Key_Return:
1600 case Qt::Key_E: 1600 case Qt::Key_E:
1601 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 1601 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
1602 mView->newEvent(); 1602 mView->newEvent();
1603 else 1603 else
1604 mView->editIncidence(); 1604 mView->editIncidence();
1605 break; 1605 break;
1606 case Qt::Key_Plus: 1606 case Qt::Key_Plus:
1607 size = p->mHourSize +2; 1607 size = p->mHourSize +2;
1608 if ( size <= 18 ) 1608 if ( size <= 18 )
1609 configureAgenda( size ); 1609 configureAgenda( size );
1610 break; 1610 break;
1611 case Qt::Key_Minus: 1611 case Qt::Key_Minus:
1612 size = p->mHourSize - 2; 1612 size = p->mHourSize - 2;
1613 if ( size >= 4 ) 1613 if ( size >= 4 )
1614 configureAgenda( size ); 1614 configureAgenda( size );
1615 break; 1615 break;
1616 1616
1617 1617
1618 default: 1618 default:
1619 e->ignore(); 1619 e->ignore();
1620 } 1620 }
1621 if ( pro > 0 ) { 1621 if ( pro > 0 ) {
1622 mView->selectFilter( pro-1 ); 1622 mView->selectFilter( pro-1 );
1623 } 1623 }
1624 if ( showSelectedDates ) { 1624 if ( showSelectedDates ) {
1625 ;// setCaptionToDates(); 1625 ;// setCaptionToDates();
1626 } 1626 }
1627 1627
1628} 1628}
1629 1629
1630void MainWindow::fillFilterMenu() 1630void MainWindow::fillFilterMenu()
1631{ 1631{
1632 selectFilterMenu->clear(); 1632 selectFilterMenu->clear();
1633 bool disable = false; 1633 bool disable = false;
1634 if ( mView->filterView()->filtersEnabled() ) { 1634 if ( mView->filterView()->filtersEnabled() ) {
1635 selectFilterMenu->insertItem(i18n ( "Turn filter off" ), 0 ); 1635 selectFilterMenu->insertItem(i18n ( "Turn filter off" ), 0 );
1636 } 1636 }
1637 else { 1637 else {
1638 selectFilterMenu->insertItem(i18n ( "Turn filter on" ), 0 ); 1638 selectFilterMenu->insertItem(i18n ( "Turn filter on" ), 0 );
1639 disable = true; 1639 disable = true;
1640 } 1640 }
1641 selectFilterMenu->insertSeparator(); 1641 selectFilterMenu->insertSeparator();
1642 QPtrList<CalFilter> fili = mView->filters(); 1642 QPtrList<CalFilter> fili = mView->filters();
1643 CalFilter *curfilter = mView->filterView()->selectedFilter(); 1643 CalFilter *curfilter = mView->filterView()->selectedFilter();
1644 CalFilter *filter = fili.first(); 1644 CalFilter *filter = fili.first();
1645 int iii = 1; 1645 int iii = 1;
1646 while(filter) { 1646 while(filter) {
1647 selectFilterMenu->insertItem( filter->name(), iii ); 1647 selectFilterMenu->insertItem( filter->name(), iii );
1648 if ( filter == curfilter) 1648 if ( filter == curfilter)
1649 selectFilterMenu->setItemChecked( iii, true ); 1649 selectFilterMenu->setItemChecked( iii, true );
1650 if ( disable ) 1650 if ( disable )
1651 selectFilterMenu->setItemEnabled( iii, false ); 1651 selectFilterMenu->setItemEnabled( iii, false );
1652 filter = fili.next(); 1652 filter = fili.next();
1653 ++iii; 1653 ++iii;
1654 } 1654 }
1655} 1655}
1656void MainWindow::selectFilter( int fil ) 1656void MainWindow::selectFilter( int fil )
1657{ 1657{
1658 if ( fil == 0 ) { 1658 if ( fil == 0 ) {
1659 mView->toggleFilerEnabled( ); 1659 mView->toggleFilerEnabled( );
1660 } else { 1660 } else {
1661 mView->selectFilter( fil-1 ); 1661 mView->selectFilter( fil-1 );
1662 } 1662 }
1663} 1663}
1664void MainWindow::configureToolBar( int item ) 1664void MainWindow::configureToolBar( int item )
1665{ 1665{
1666 1666
1667 configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) ); 1667 configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) );
1668 KOPrefs *p = KOPrefs::instance(); 1668 KOPrefs *p = KOPrefs::instance();
1669 p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 ); 1669 p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 );
1670 p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 ); 1670 p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 );
1671 p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 ); 1671 p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 );
1672 p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 ); 1672 p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 );
1673 p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 ); 1673 p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 );
1674 p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 ); 1674 p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 );
1675 p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 ); 1675 p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 );
1676 p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 ); 1676 p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 );
1677 p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 ); 1677 p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 );
1678 p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 ); 1678 p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 );
1679 p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 ); 1679 p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 );
1680 p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 ); 1680 p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 );
1681 p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 ); 1681 p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 );
1682 p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 ); 1682 p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 );
1683 p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 ); 1683 p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 );
1684 p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 ); 1684 p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 );
1685 p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 ); 1685 p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 );
1686 p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 ); 1686 p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 );
1687 p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 ); 1687 p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 );
1688 // initActions(); 1688 // initActions();
1689} 1689}
1690 1690
1691void MainWindow::setCaptionToDates() 1691void MainWindow::setCaptionToDates()
1692{ 1692{
1693 QString selDates; 1693 QString selDates;
1694 selDates = KGlobal::locale()->formatDate(mView->startDate(), true); 1694 selDates = KGlobal::locale()->formatDate(mView->startDate(), true);
1695 if (mView->startDate() < mView->endDate() ) 1695 if (mView->startDate() < mView->endDate() )
1696 selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true); 1696 selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true);
1697 setCaption( i18n("Dates: ") + selDates ); 1697 setCaption( i18n("Dates: ") + selDates );
1698 1698
1699} 1699}
1700// parameter item == 0: reinit 1700// parameter item == 0: reinit
1701void MainWindow::configureAgenda( int item ) 1701void MainWindow::configureAgenda( int item )
1702{ 1702{
1703 1703
1704 KOPrefs *p = KOPrefs::instance(); 1704 KOPrefs *p = KOPrefs::instance();
1705 1705
1706 int i; 1706 int i;
1707 if ( item == 1 ) { 1707 if ( item == 1 ) {
1708 mView->toggleAllDaySize(); 1708 mView->toggleAllDaySize();
1709 return; 1709 return;
1710 } 1710 }
1711 // do not allow 4 for widgets higher than 480 1711 // do not allow 4 for widgets higher than 480
1712 // if ( QApplication::desktop()->height() > 480 ) { 1712 // if ( QApplication::desktop()->height() > 480 ) {
1713// if ( item == 4 ) 1713// if ( item == 4 )
1714// item = 6; 1714// item = 6;
1715// } 1715// }
1716 for ( i = 4; i <= 18; i= i+2 ) 1716 for ( i = 4; i <= 18; i= i+2 )
1717 configureAgendaMenu->setItemChecked( i, false ); 1717 configureAgendaMenu->setItemChecked( i, false );
1718 configureAgendaMenu->setItemChecked( item, true ); 1718 configureAgendaMenu->setItemChecked( item, true );
1719 if ( p->mHourSize == item ) 1719 if ( p->mHourSize == item )
1720 return; 1720 return;
1721 p->mHourSize=item; 1721 p->mHourSize=item;
1722 mView->viewManager()->agendaView()->updateConfig(); 1722 mView->viewManager()->agendaView()->updateConfig();
1723} 1723}
1724 1724
1725void MainWindow::saveCalendar() 1725void MainWindow::saveCalendar()
1726{ 1726{
1727 QString fn = KOPrefs::instance()->mLastSaveFile; 1727 QString fn = KOPrefs::instance()->mLastSaveFile;
1728 fn = KFileDialog::getSaveFileName( fn, i18n("Save backup filename"), this ); 1728 fn = KFileDialog::getSaveFileName( fn, i18n("Save backup filename"), this );
1729 1729
1730 if ( fn == "" ) 1730 if ( fn == "" )
1731 return; 1731 return;
1732 QFileInfo info; 1732 QFileInfo info;
1733 info.setFile( fn ); 1733 info.setFile( fn );
1734 QString mes; 1734 QString mes;
1735 bool createbup = true; 1735 bool createbup = true;
1736 if ( info. exists() ) { 1736 if ( info. exists() ) {
1737 mes = i18n("Backup file\nalready exists!\nOld backup file from:\n%1\nOverwrite?\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )) ; 1737 mes = i18n("Backup file\nalready exists!\nOld backup file from:\n%1\nOverwrite?\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )) ;
1738 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 1738 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
1739 i18n("Overwrite!"), i18n("Cancel"), 0, 1739 i18n("Overwrite!"), i18n("Cancel"), 0,
1740 0, 1 ); 1740 0, 1 );
1741 if ( result != 0 ) { 1741 if ( result != 0 ) {
1742 createbup = false; 1742 createbup = false;
1743 } 1743 }
1744 } 1744 }
1745 if ( createbup ) { 1745 if ( createbup ) {
1746 mView->saveCalendar( fn ); 1746 mView->saveCalendar( fn );
1747 mes = i18n("KO/Pi:Saved %1").arg(fn); 1747 mes = i18n("KO/Pi:Saved %1").arg(fn);
1748 KOPrefs::instance()->mLastSaveFile = fn; 1748 KOPrefs::instance()->mLastSaveFile = fn;
1749 setCaption(mes); 1749 setCaption(mes);
1750 } 1750 }
1751} 1751}
1752void MainWindow::loadCalendar() 1752void MainWindow::loadCalendar()
1753{ 1753{
1754 1754
1755 QString fn = KOPrefs::instance()->mLastLoadFile; 1755 QString fn = KOPrefs::instance()->mLastLoadFile;
1756 fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this ); 1756 fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this );
1757 1757
1758 if ( fn == "" ) 1758 if ( fn == "" )
1759 return; 1759 return;
1760 QFileInfo info; 1760 QFileInfo info;
1761 info.setFile( fn ); 1761 info.setFile( fn );
1762 QString mess; 1762 QString mess;
1763 bool loadbup = true; 1763 bool loadbup = true;
1764 if ( info. exists() ) { 1764 if ( info. exists() ) {
1765 mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 1765 mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
1766 int result = QMessageBox::warning( this, "KO/Pi: Warning!", 1766 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
1767 mess, 1767 mess,
1768 i18n("Load!"), i18n("Cancel"), 0, 1768 i18n("Load!"), i18n("Cancel"), 0,
1769 0, 1 ); 1769 0, 1 );
1770 if ( result != 0 ) { 1770 if ( result != 0 ) {
1771 loadbup = false; 1771 loadbup = false;
1772 } 1772 }
1773 } else { 1773 } else {
1774 QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1774 QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1775 i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0, 1775 i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0,
1776 0, 1 ); 1776 0, 1 );
1777 1777
1778 return; 1778 return;
1779 } 1779 }
1780 if ( loadbup ) { 1780 if ( loadbup ) {
1781 mView->openCalendar( fn ); 1781 mView->openCalendar( fn );
1782 KOPrefs::instance()->mLastLoadFile = fn; 1782 KOPrefs::instance()->mLastLoadFile = fn;
1783 mess = i18n("KO/Pi:Loaded %1").arg(fn) ; 1783 mess = i18n("KO/Pi:Loaded %1").arg(fn) ;
1784 setCaption(mess); 1784 setCaption(mess);
1785 } 1785 }
1786 1786
1787} 1787}
1788void MainWindow::quickImportIcal() 1788void MainWindow::quickImportIcal()
1789{ 1789{
1790 importFile( KOPrefs::instance()->mLastImportFile, false ); 1790 importFile( KOPrefs::instance()->mLastImportFile, false );
1791} 1791}
1792void MainWindow::importFile( QString fn, bool quick ) 1792void MainWindow::importFile( QString fn, bool quick )
1793{ 1793{
1794 QFileInfo info; 1794 QFileInfo info;
1795 info.setFile( fn ); 1795 info.setFile( fn );
1796 QString mess; 1796 QString mess;
1797 bool loadbup = true; 1797 bool loadbup = true;
1798 if ( !info. exists() ) { 1798 if ( !info. exists() ) {
1799 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); 1799 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30));
1800 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1800 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1801 mess ); 1801 mess );
1802 return; 1802 return;
1803 } 1803 }
1804 int result = 0; 1804 int result = 0;
1805 if ( !quick ) { 1805 if ( !quick ) {
1806 mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 1806 mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
1807 result = QMessageBox::warning( this, "KO/Pi: Warning!", 1807 result = QMessageBox::warning( this, "KO/Pi: Warning!",
1808 mess, 1808 mess,
1809 "Import", "Cancel", 0, 1809 "Import", "Cancel", 0,
1810 0, 1 ); 1810 0, 1 );
1811 } 1811 }
1812 if ( result == 0 ) { 1812 if ( result == 0 ) {
1813 if ( mView->openCalendar( fn, true )) { 1813 if ( mView->openCalendar( fn, true )) {
1814 KOPrefs::instance()->mLastImportFile = fn; 1814 KOPrefs::instance()->mLastImportFile = fn;
1815 setCaption(i18n("Imported file successfully")); 1815 setCaption(i18n("Imported file successfully"));
1816 } else { 1816 } else {
1817 setCaption(i18n("Error importing file")); 1817 setCaption(i18n("Error importing file"));
1818 } 1818 }
1819 } 1819 }
1820} 1820}
1821 1821
1822void MainWindow::importIcal() 1822void MainWindow::importIcal()
1823{ 1823{
1824 1824
1825 QString fn =KOPrefs::instance()->mLastImportFile; 1825 QString fn =KOPrefs::instance()->mLastImportFile;
1826 1826
1827 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); 1827 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this );
1828 if ( fn == "" ) 1828 if ( fn == "" )
1829 return; 1829 return;
1830 importFile( fn, true ); 1830 importFile( fn, true );
1831 1831
1832} 1832}
1833 1833
1834void MainWindow::exportVCalendar() 1834void MainWindow::exportVCalendar()
1835{ 1835{
1836 QString fn = KOPrefs::instance()->mLastVcalFile; 1836 QString fn = KOPrefs::instance()->mLastVcalFile;
1837 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); 1837 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this );
1838 if ( fn == "" ) 1838 if ( fn == "" )
1839 return; 1839 return;
1840 QFileInfo info; 1840 QFileInfo info;
1841 info.setFile( fn ); 1841 info.setFile( fn );
1842 QString mes; 1842 QString mes;
1843 bool createbup = true; 1843 bool createbup = true;
1844 if ( info. exists() ) { 1844 if ( info. exists() ) {
1845 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 1845 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
1846 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 1846 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
1847 i18n("Overwrite!"), i18n("Cancel"), 0, 1847 i18n("Overwrite!"), i18n("Cancel"), 0,
1848 0, 1 ); 1848 0, 1 );
1849 if ( result != 0 ) { 1849 if ( result != 0 ) {
1850 createbup = false; 1850 createbup = false;
1851 } 1851 }
1852 } 1852 }
1853 if ( createbup ) { 1853 if ( createbup ) {
1854 if ( mView->exportVCalendar( fn ) ) { 1854 if ( mView->exportVCalendar( fn ) ) {
1855 KOPrefs::instance()->mLastVcalFile = fn; 1855 KOPrefs::instance()->mLastVcalFile = fn;
1856 if ( fn.length() > 20 ) 1856 if ( fn.length() > 20 )
1857 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; 1857 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ;
1858 else 1858 else
1859 mes = i18n("KO/Pi:Exported to %1").arg(fn ); 1859 mes = i18n("KO/Pi:Exported to %1").arg(fn );
1860 setCaption(mes); 1860 setCaption(mes);
1861 } 1861 }
1862 } 1862 }
1863 1863
1864} 1864}
1865QString MainWindow::getPassword( ) 1865QString MainWindow::getPassword( )
1866{ 1866{
1867 QString retfile = ""; 1867 QString retfile = "";
1868 QDialog dia ( this, "input-dialog", true ); 1868 QDialog dia ( this, "input-dialog", true );
1869 QLineEdit lab ( &dia ); 1869 QLineEdit lab ( &dia );
1870 lab.setEchoMode( QLineEdit::Password ); 1870 lab.setEchoMode( QLineEdit::Password );
1871 QVBoxLayout lay( &dia ); 1871 QVBoxLayout lay( &dia );
1872 lay.setMargin(7); 1872 lay.setMargin(7);
1873 lay.setSpacing(7); 1873 lay.setSpacing(7);
1874 lay.addWidget( &lab); 1874 lay.addWidget( &lab);
1875 dia.setFixedSize( 230,50 ); 1875 dia.setFixedSize( 230,50 );
1876 dia.setCaption( i18n("Enter password") ); 1876 dia.setCaption( i18n("Enter password") );
1877 QPushButton pb ( "OK", &dia); 1877 QPushButton pb ( "OK", &dia);
1878 lay.addWidget( &pb ); 1878 lay.addWidget( &pb );
1879 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 1879 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
1880 dia.show(); 1880 dia.show();
1881 int res = dia.exec(); 1881 int res = dia.exec();
1882 if ( res ) 1882 if ( res )
1883 retfile = lab.text(); 1883 retfile = lab.text();
1884 dia.hide(); 1884 dia.hide();
1885 qApp->processEvents(); 1885 qApp->processEvents();
1886 return retfile; 1886 return retfile;
1887 1887
1888} 1888}
1889 1889
1890void MainWindow::enableQuick() 1890void MainWindow::enableQuick()
1891{ 1891{
1892 QString passWordPiSync = "bhdrvmk"; 1892 QString passWordPiSync = "bhdrvmk";
1893 QString retfile = ""; 1893 QString retfile = "";
1894 QDialog dia ( this, "input-dialog", true ); 1894 QDialog dia ( this, "input-dialog", true );
1895 QLineEdit lab ( &dia ); 1895 QLineEdit lab ( &dia );
1896 QVBoxLayout lay( &dia ); 1896 QVBoxLayout lay( &dia );
1897 lab.setText( KOPrefs::instance()->mPassiveSyncPort ); 1897 lab.setText( KOPrefs::instance()->mPassiveSyncPort );
1898 lay.setMargin(7); 1898 lay.setMargin(7);
1899 lay.setSpacing(7); 1899 lay.setSpacing(7);
1900 QLabel label ( i18n("Port number (Default: 9197)"), &dia ); 1900 QLabel label ( i18n("Port number (Default: 9197)"), &dia );
1901 lay.addWidget( &label); 1901 lay.addWidget( &label);
1902 lay.addWidget( &lab); 1902 lay.addWidget( &lab);
1903 1903
1904 QLineEdit lepw ( &dia ); 1904 QLineEdit lepw ( &dia );
1905 lepw.setText( "abc" ); 1905 lepw.setText( "abc" );
1906 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 1906 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
1907 lay.addWidget( &label2); 1907 lay.addWidget( &label2);
1908 lay.addWidget( &lepw); 1908 lay.addWidget( &lepw);
1909 dia.setFixedSize( 230,80 ); 1909 dia.setFixedSize( 230,80 );
1910 dia.setCaption( i18n("Enter port for Pi-Sync") ); 1910 dia.setCaption( i18n("Enter port for Pi-Sync") );
1911 QPushButton pb ( "OK", &dia); 1911 QPushButton pb ( "OK", &dia);
1912 lay.addWidget( &pb ); 1912 lay.addWidget( &pb );
1913 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 1913 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
1914 dia.show(); 1914 dia.show();
1915 int res = dia.exec(); 1915 int res = dia.exec();
1916 if ( res ) 1916 if ( res )
1917 retfile = lab.text(); 1917 retfile = lab.text();
1918 else 1918 else
1919 return; 1919 return;
1920 dia.hide(); 1920 dia.hide();
1921 passWordPiSync = lepw.text(); 1921 passWordPiSync = lepw.text();
1922 qApp->processEvents(); 1922 qApp->processEvents();
1923 KOPrefs::instance()->mPassiveSyncPort = retfile; 1923 KOPrefs::instance()->mPassiveSyncPort = retfile;
1924 bool ok; 1924 bool ok;
1925 Q_UINT16 port = retfile.toUInt(&ok); 1925 Q_UINT16 port = retfile.toUInt(&ok);
1926 if ( ! ok ) { 1926 if ( ! ok ) {
1927 KMessageBox::information( this, i18n("No valid port")); 1927 KMessageBox::information( this, i18n("No valid port"));
1928 return; 1928 return;
1929 } 1929 }
1930 qDebug("port %d ", port); 1930 qDebug("port %d ", port);
1931 mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); 1931 mServerSocket = new KServerSocket ( passWordPiSync, port ,1 );
1932 mServerSocket->setFileName( defaultFileName() );
1932 qDebug("connected "); 1933 qDebug("connected ");
1933 if ( !mServerSocket->ok() ) { 1934 if ( !mServerSocket->ok() ) {
1934 qWarning("Failed to bind to port %d", port); 1935 qWarning("Failed to bind to port %d", port);
1935 delete mServerSocket; 1936 delete mServerSocket;
1936 mServerSocket = 0; 1937 mServerSocket = 0;
1937 return; 1938 return;
1938 } 1939 }
1939 connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); 1940 connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) );
1940 connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); 1941 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) );
1942 // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) );
1943 //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) );
1941} 1944}
1942void MainWindow::sendFile(QSocket* socket) 1945void MainWindow::sendFile(QSocket* socket)
1943{ 1946{
1944 setCaption( i18n("Received request for file") ); 1947 setCaption( i18n("Received request for file") );
1945 qDebug("MainWindow::sendFile(QSocket* s) "); 1948 qDebug("MainWindow::sendFile(QSocket* s) ");
1946 if ( mSyncActionDialog ) 1949 if ( mSyncActionDialog )
1947 delete mSyncActionDialog; 1950 delete mSyncActionDialog;
1948 mSyncActionDialog = new QDialog ( this, "input-dialog", true ); 1951 mSyncActionDialog = new QDialog ( this, "input-dialog", true );
1949 mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING")); 1952 mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING"));
1950 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog ); 1953 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog );
1951 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1954 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1952 lay->addWidget( label); 1955 lay->addWidget( label);
1953 lay->setMargin(7); 1956 lay->setMargin(7);
1954 lay->setSpacing(7); 1957 lay->setSpacing(7);
1955 mSyncActionDialog->setFixedSize( 200,100 ); 1958 mSyncActionDialog->setFixedSize( 200,100 );
1956 mSyncActionDialog->show(); 1959 mSyncActionDialog->show();
1957 qDebug("saving ... "); 1960 qDebug("saving ... ");
1958 save(); 1961 save();
1959 qApp->processEvents(); 1962 qApp->processEvents();
1960 QString fileName = defaultFileName(); 1963 QString fileName = defaultFileName();
1961 QFile file( fileName ); 1964 QFile file( fileName );
1962 if (!file.open( IO_ReadOnly ) ) { 1965 if (!file.open( IO_ReadOnly ) ) {
1963 setCaption( i18n("Error open file") ); 1966 setCaption( i18n("Error open file") );
1964 delete mSyncActionDialog; 1967 delete mSyncActionDialog;
1965 mSyncActionDialog = 0; 1968 mSyncActionDialog = 0;
1966 qDebug("error open cal file "); 1969 qDebug("error open cal file ");
1967 return ; 1970 return ;
1968 1971
1969 } 1972 }
1970 setCaption( i18n("Sending file...") ); 1973 setCaption( i18n("Sending file...") );
1971 QTextStream ts( &file ); 1974 QTextStream ts( &file );
1972 ts.setCodec( QTextCodec::codecForName("utf8") ); 1975 ts.setCodec( QTextCodec::codecForName("utf8") );
1973 QTextStream os( socket ); 1976 QTextStream os( socket );
1974 os.setCodec( QTextCodec::codecForName("utf8") ); 1977 os.setCodec( QTextCodec::codecForName("utf8") );
1975 //os.setEncoding( QTextStream::UnicodeUTF8 ); 1978 //os.setEncoding( QTextStream::UnicodeUTF8 );
1976 while ( ! ts.atEnd() ) { 1979 while ( ! ts.atEnd() ) {
1977 os << ts.readLine() << "\n"; 1980 os << ts.readLine() << "\n";
1978 } 1981 }
1979 //os << ts.read(); 1982 //os << ts.read();
1980 socket->close(); 1983 socket->close();
1981 file.close(); 1984 file.close();
1982 setCaption( i18n("File sent. Waiting to get back synced file") ); 1985 setCaption( i18n("File sent. Waiting to get back synced file") );
1983 qDebug("file sent "); 1986 qDebug("file sent ");
1984} 1987}
1985void MainWindow::getFile(QSocket* socket) 1988void MainWindow::getFile( bool success )
1986{ 1989{
1990 if ( ! success ) {
1991 setCaption( i18n("Error receiving file. Nothing changed!") );
1992 return;
1993 }
1994 // pending adjust time for watchSavedFile()
1995 //mView->watchSavedFile();
1996 mView->openCalendar( defaultFileName() );
1997 setCaption( i18n("Pi-Sync successful!") );
1998
1999
2000#if 0
1987 setCaption( i18n("Receiving synced file...") ); 2001 setCaption( i18n("Receiving synced file...") );
1988 2002
1989 piTime.start(); 2003 piTime.start();
1990 piSocket = socket; 2004 piSocket = socket;
1991 piFileString = ""; 2005 piFileString = "";
1992 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 2006 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1993 2007#endif
1994 2008
1995} 2009}
1996void MainWindow::readBackFileFromSocket() 2010void MainWindow::readBackFileFromSocket()
1997{ 2011{
1998 qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 2012 qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1999 while ( piSocket->canReadLine () ) { 2013 while ( piSocket->canReadLine () ) {
2000 piTime.restart(); 2014 piTime.restart();
2001 QString line = piSocket->readLine (); 2015 QString line = piSocket->readLine ();
2002 piFileString += line; 2016 piFileString += line;
2003 qDebug("readline: %s ", line.latin1()); 2017 qDebug("readline: %s ", line.latin1());
2004 setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 2018 setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
2005 2019
2006 } 2020 }
2007 if ( piTime.elapsed () < 3000 ) { 2021 if ( piTime.elapsed () < 3000 ) {
2008 // wait for more 2022 // wait for more
2009 qDebug("waitformore "); 2023 qDebug("waitformore ");
2010 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 2024 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
2011 return; 2025 return;
2012 } 2026 }
2013 QString fileName = defaultFileName(); 2027 QString fileName = defaultFileName();
2014 QFile file ( fileName ); 2028 QFile file ( fileName );
2015 if (!file.open( IO_WriteOnly ) ) { 2029 if (!file.open( IO_WriteOnly ) ) {
2016 setCaption( i18n("Error open file for writing!") ); 2030 setCaption( i18n("Error open file for writing!") );
2017 delete mSyncActionDialog; 2031 delete mSyncActionDialog;
2018 mSyncActionDialog = 0; 2032 mSyncActionDialog = 0;
2019 qDebug("error open cal file "); 2033 qDebug("error open cal file ");
2020 piFileString = ""; 2034 piFileString = "";
2021 return ; 2035 return ;
2022 2036
2023 } 2037 }
2024 2038
2025 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 2039 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
2026 QTextStream ts ( &file ); 2040 QTextStream ts ( &file );
2027 ts.setCodec( QTextCodec::codecForName("utf8") ); 2041 ts.setCodec( QTextCodec::codecForName("utf8") );
2028 qDebug("finish "); 2042 qDebug("finish ");
2029 setCaption( i18n("Writing file to disk...") ); 2043 setCaption( i18n("Writing file to disk...") );
2030 ts << piFileString; 2044 ts << piFileString;
2031 setCaption( i18n("File received - reloading calendar...") ); 2045 setCaption( i18n("File received - reloading calendar...") );
2032 piSocket->close(); 2046 piSocket->close();
2033 file.close(); 2047 file.close();
2034 mView->watchSavedFile(); 2048 mView->watchSavedFile();
2035 mView->openCalendar( defaultFileName() ); 2049 mView->openCalendar( defaultFileName() );
2036 setCaption( i18n("Pi-Sync successful!") ); 2050 setCaption( i18n("Pi-Sync successful!") );
2037 delete mSyncActionDialog; 2051 delete mSyncActionDialog;
2038 mSyncActionDialog = 0; 2052 mSyncActionDialog = 0;
2039 piFileString = ""; 2053 piFileString = "";
2040 2054
2041 2055
2042} 2056}
2043void MainWindow::endConnect() 2057void MainWindow::endConnect()
2044{ 2058{
2045 setCaption( i18n("No file received - syncing successful") ); 2059 setCaption( i18n("No file received - syncing successful") );
2046 delete mSyncActionDialog; 2060 delete mSyncActionDialog;
2047 mSyncActionDialog = 0; 2061 mSyncActionDialog = 0;
2048} 2062}
2049void MainWindow::performQuick() 2063void MainWindow::performQuick()
2050{ 2064{
2051 2065
2052 setCaption( i18n("Please input connection settings") ); 2066 setCaption( i18n("Please input connection settings") );
2053 QString retfile = ""; 2067 QString retfile = "";
2054 QDialog dia ( this, "input-dialog", true ); 2068 QDialog dia ( this, "input-dialog", true );
2055 QLineEdit lab ( &dia ); 2069 QLineEdit lab ( &dia );
2056 QVBoxLayout lay( &dia ); 2070 QVBoxLayout lay( &dia );
2057 QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); 2071 QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia );
2058 lay.addWidget( &label); 2072 lay.addWidget( &label);
2059 lab.setText( KOPrefs::instance()->mActiveSyncIP ); 2073 lab.setText( KOPrefs::instance()->mActiveSyncIP );
2060 lay.setMargin(7); 2074 lay.setMargin(7);
2061 lay.setSpacing(7); 2075 lay.setSpacing(7);
2062 lay.addWidget( &lab); 2076 lay.addWidget( &lab);
2063 QLabel label2 ( i18n("Port number (Default: 9197)"), &dia ); 2077 QLabel label2 ( i18n("Port number (Default: 9197)"), &dia );
2064 lay.addWidget( &label2); 2078 lay.addWidget( &label2);
2065 QLineEdit lab2 ( &dia ); 2079 QLineEdit lab2 ( &dia );
2066 lab2.setText( KOPrefs::instance()->mActiveSyncPort ); 2080 lab2.setText( KOPrefs::instance()->mActiveSyncPort );
2067 lay.addWidget( &lab2); 2081 lay.addWidget( &lab2);
2068 2082
2069 QLineEdit lepw ( &dia ); 2083 QLineEdit lepw ( &dia );
2070 lepw.setText( mPassWordPiSync ); 2084 lepw.setText( mPassWordPiSync );
2071 QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia ); 2085 QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia );
2072 lay.addWidget( &label3); 2086 lay.addWidget( &label3);
2073 lay.addWidget( &lepw); 2087 lay.addWidget( &lepw);
2074 2088
2075 dia.setFixedSize( 230,200 ); 2089 dia.setFixedSize( 230,200 );
2076 dia.setCaption( i18n("Enter port for Pi-Sync ") ); 2090 dia.setCaption( i18n("Enter port for Pi-Sync ") );
2077 QPushButton pb ( "OK", &dia); 2091 QPushButton pb ( "OK", &dia);
2078 lay.addWidget( &pb ); 2092 lay.addWidget( &pb );
2079 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2093 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2080 dia.show(); 2094 dia.show();
2081 int res = dia.exec(); 2095 int res = dia.exec();
2082 if ( !res ) { 2096 if ( !res ) {
2083 setCaption( i18n("Syncing cancelled!") ); 2097 setCaption( i18n("Syncing cancelled!") );
2084 return; 2098 return;
2085 } 2099 }
2086 mPassWordPiSync = lepw.text(); 2100 mPassWordPiSync = lepw.text();
2087 dia.hide(); 2101 dia.hide();
2088 KOPrefs::instance()->mActiveSyncPort = lab2.text(); 2102 KOPrefs::instance()->mActiveSyncPort = lab2.text();
2089 KOPrefs::instance()->mActiveSyncIP = lab.text(); 2103 KOPrefs::instance()->mActiveSyncIP = lab.text();
2090 qApp->processEvents(); 2104 qApp->processEvents();
2091 performQuickQuick(); 2105 performQuickQuick();
2092} 2106}
2093 2107
2094void MainWindow::performQuickQuick() 2108void MainWindow::performQuickQuick()
2095{ 2109{
2096 // setCaption( i18n("") ); 2110 // setCaption( i18n("") );
2097 2111
2098 bool ok; 2112 bool ok;
2099 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); 2113 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok);
2100 if ( ! ok ) { 2114 if ( ! ok ) {
2101 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 2115 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
2102 return; 2116 return;
2103 } 2117 }
2104 mCommandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this ); 2118 mCommandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this );
2105 connect( mCommandSocket, SIGNAL(commandFinished( bool )), this, SLOT(deleteCommandSocket(bool)) ); 2119 connect( mCommandSocket, SIGNAL(commandFinished( bool )), this, SLOT(deleteCommandSocket(bool)) );
2106 setCaption( i18n("Sending request for remote file ...") ); 2120 setCaption( i18n("Sending request for remote file ...") );
2107 QString fileName; 2121 QString fileName;
2108#ifdef _WIN32_ 2122#ifdef _WIN32_
2109 fileName = defaultFileName() +"sync"; 2123 fileName = defaultFileName() +"sync";
2110#else 2124#else
2111 fileName = "/tmp/kopitempfile.ics"; 2125 fileName = "/tmp/kopitempfile.ics";
2112#endif 2126#endif
2113 mCommandSocket->readFile( fileName ); 2127 mCommandSocket->readFile( fileName );
2114} 2128}
2115void MainWindow::deleteCommandSocket( bool success) 2129void MainWindow::deleteCommandSocket( bool success)
2116{ 2130{
2117 if ( ! success ) { 2131 if ( ! success ) {
2118 setCaption( i18n("ERROR:Receiving remote file failed.") ); 2132 setCaption( i18n("ERROR:Receiving remote file failed.") );
2119 // pending : send stop 2133 // pending : send stop
2120 return; 2134 return;
2121 2135
2122 } 2136 }
2123 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 2137 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
2124 delete mCommandSocket; 2138 delete mCommandSocket;
2125} 2139}
2126void MainWindow::deleteCommandSocketFinish() 2140void MainWindow::deleteCommandSocketFinish()
2127{ 2141{
2128 if ( ! mCommandSocketFinish) 2142 if ( ! mCommandSocketFinish)
2129 return; 2143 return;
2130 // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); 2144 // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() "));
2131 qDebug("MainWindow::deletemCommandSocketFinish() "); 2145 qDebug("MainWindow::deletemCommandSocketFinish() ");
2132 delete mCommandSocketFinish; 2146 delete mCommandSocketFinish;
2133 mCommandSocketFinish = 0; 2147 mCommandSocketFinish = 0;
2134} 2148}
2135void MainWindow::readFileFromSocket() 2149void MainWindow::readFileFromSocket()
2136{ 2150{
2137 // mTimerCommandSocket->stop(); 2151 // mTimerCommandSocket->stop();
2138 setCaption( i18n("Receiving remote file ...") ); 2152 setCaption( i18n("Receiving remote file ...") );
2139 qDebug("MainWindow::readFileFromSocket() "); 2153 qDebug("MainWindow::readFileFromSocket() ");
2140 QString fileName; 2154 QString fileName;
2141#ifdef _WIN32_ 2155#ifdef _WIN32_
2142 fileName = defaultFileName() +"sync"; 2156 fileName = defaultFileName() +"sync";
2143#else 2157#else
2144 fileName = "/tmp/kopitempfile.ics"; 2158 fileName = "/tmp/kopitempfile.ics";
2145#endif 2159#endif
2146 2160
2147 setCaption( i18n("Remote file saved to temp file.") ); 2161 setCaption( i18n("Remote file saved to temp file.") );
2148 //mCommandSocket = 0; 2162 //mCommandSocket = 0;
2149 mCurrentSyncProfile = 2 ; // last file 2163 mCurrentSyncProfile = 2 ; // last file
2150 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); 2164 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
2151 mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); 2165 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
2152 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2166 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2153 KSyncProfile* temp = new KSyncProfile (); 2167 KSyncProfile* temp = new KSyncProfile ();
2154 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2168 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2155 temp->readConfig(&config); 2169 temp->readConfig(&config);
2156 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2170 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2157 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 2171 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
2158 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2172 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2159 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2173 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2160 KOPrefs::instance()->mWriteBackInFuture = 0; 2174 KOPrefs::instance()->mWriteBackInFuture = 0;
2161 if ( temp->getWriteBackFuture() ) 2175 if ( temp->getWriteBackFuture() )
2162 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2176 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2163 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 2177 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2164 delete temp; 2178 delete temp;
2165 setCaption( i18n("Remote file saved to temp file.") ); 2179 setCaption( i18n("Remote file saved to temp file.") );
2166 if ( ! syncWithFile( fileName , true ) ) { 2180 if ( ! syncWithFile( fileName , true ) ) {
2167 setCaption( i18n("Syncing failed.") ); 2181 setCaption( i18n("Syncing failed.") );
2168 qDebug("Syncing failed "); 2182 qDebug("Syncing failed ");
2169 return; 2183 return;
2170 } 2184 }
2171 2185
2172 if ( !mCommandSocketFinish ) { 2186 if ( !mCommandSocketFinish ) {
2173 mCommandSocketFinish = new QSocket( this ); 2187 mCommandSocketFinish = new QSocket( this );
2174 connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); 2188 connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) );
2175 } 2189 }
2176 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); 2190 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() );
2177 2191
2178 QString host = KOPrefs::instance()->mActiveSyncIP; 2192 QString host = KOPrefs::instance()->mActiveSyncIP;
2179 QFile file2( fileName ); 2193 QFile file2( fileName );
2180 if (!file2.open( IO_ReadOnly ) ) { 2194 if (!file2.open( IO_ReadOnly ) ) {
2181 setCaption( i18n("Error: Cannot open temp file for read.") ); 2195 setCaption( i18n("Error: Cannot open temp file for read.") );
2182 qDebug("error open cal file "); 2196 qDebug("error open cal file ");
2183 return ; 2197 return ;
2184 2198
2185 } 2199 }
2186 QTextStream ts2( &file2 ); 2200 QTextStream ts2( &file2 );
2187 ts2.setCodec( QTextCodec::codecForName("utf8") ); 2201 ts2.setCodec( QTextCodec::codecForName("utf8") );
2188 QTextStream os2( mCommandSocketFinish ); 2202 QTextStream os2( mCommandSocketFinish );
2189 os2.setCodec( QTextCodec::codecForName("utf8") ); 2203 os2.setCodec( QTextCodec::codecForName("utf8") );
2190 //os.setEncoding( QTextStream::UnicodeUTF8 ); 2204 //os.setEncoding( QTextStream::UnicodeUTF8 );
2191 if ( KOPrefs::instance()->mWriteBackFile ) { 2205 if ( KOPrefs::instance()->mWriteBackFile ) {
2192 setCaption( i18n("Sending back synced file...") ); 2206 setCaption( i18n("Sending back synced file...") );
2193 os2 << "PUT " << mPassWordPiSync << "\r\n";; 2207 os2 << "PUT " << mPassWordPiSync << "\r\n";;
2194 while ( ! ts2.atEnd() ) { 2208 while ( ! ts2.atEnd() ) {
2195 os2 << ts2.readLine() << "\n"; 2209 os2 << ts2.readLine() << "\n";
2196 } 2210 }
2197 } else { 2211 } else {
2198 os2 << "STOP\r\n"; 2212 os2 << "STOP\r\n";
2199 } 2213 }
2200 mCommandSocketFinish->close(); 2214 mCommandSocketFinish->close();
2201 if ( mCommandSocketFinish->state() == QSocket::Idle ) 2215 if ( mCommandSocketFinish->state() == QSocket::Idle )
2202 QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish())); 2216 QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish()));
2203 file2.close(); 2217 file2.close();
2204 qDebug("Syncing succesful! "); 2218 qDebug("Syncing succesful! ");
2205 setCaption( i18n("Pi-Sync succesful!") ); 2219 setCaption( i18n("Pi-Sync succesful!") );
2206 2220
2207 // KMessageBox::information( 0, i18n(" Pi-Sync succesful! ")); 2221 // KMessageBox::information( 0, i18n(" Pi-Sync succesful! "));
2208 2222
2209} 2223}
2210 2224
2211void MainWindow::syncLocalFile() 2225void MainWindow::syncLocalFile()
2212{ 2226{
2213 2227
2214 QString fn =KOPrefs::instance()->mLastSyncedLocalFile; 2228 QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
2215 2229
2216 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 2230 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2217 if ( fn == "" ) 2231 if ( fn == "" )
2218 return; 2232 return;
2219 //mView->setSyncDevice("local-file" ); 2233 //mView->setSyncDevice("local-file" );
2220 if ( syncWithFile( fn, false ) ) { 2234 if ( syncWithFile( fn, false ) ) {
2221 // Event* e = mView->getLastSyncEvent(); 2235 // Event* e = mView->getLastSyncEvent();
2222// e->setReadOnly( false ); 2236// e->setReadOnly( false );
2223// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 2237// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2224// e->setReadOnly( true ); 2238// e->setReadOnly( true );
2225 } 2239 }
2226 2240
2227} 2241}
2228 2242
2229bool MainWindow::syncWithFile( QString fn , bool quick ) 2243bool MainWindow::syncWithFile( QString fn , bool quick )
2230{ 2244{
2231 bool ret = false; 2245 bool ret = false;
2232 QFileInfo info; 2246 QFileInfo info;
2233 info.setFile( fn ); 2247 info.setFile( fn );
2234 QString mess; 2248 QString mess;
2235 bool loadbup = true; 2249 bool loadbup = true;
2236 if ( !info. exists() ) { 2250 if ( !info. exists() ) {
2237 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 2251 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
2238 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2252 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2239 mess ); 2253 mess );
2240 return ret; 2254 return ret;
2241 } 2255 }
2242 int result = 0; 2256 int result = 0;
2243 if ( !quick ) { 2257 if ( !quick ) {
2244 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2258 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2245 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2259 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2246 mess, 2260 mess,
2247 i18n("Sync"), i18n("Cancel"), 0, 2261 i18n("Sync"), i18n("Cancel"), 0,
2248 0, 1 ); 2262 0, 1 );
2249 if ( result ) 2263 if ( result )
2250 return false; 2264 return false;
2251 } 2265 }
2252 if ( KOPrefs::instance()->mAskForPreferences ) 2266 if ( KOPrefs::instance()->mAskForPreferences )
2253 mView->edit_sync_options(); 2267 mView->edit_sync_options();
2254 if ( result == 0 ) { 2268 if ( result == 0 ) {
2255 //qDebug("Now sycing ... "); 2269 //qDebug("Now sycing ... ");
2256 if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) ) 2270 if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) )
2257 setCaption( i18n("Synchronization successful") ); 2271 setCaption( i18n("Synchronization successful") );
2258 else 2272 else
2259 setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 2273 setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
2260 if ( ! quick ) 2274 if ( ! quick )
2261 KOPrefs::instance()->mLastSyncedLocalFile = fn; 2275 KOPrefs::instance()->mLastSyncedLocalFile = fn;
2262 slotModifiedChanged( true ); 2276 slotModifiedChanged( true );
2263 } 2277 }
2264 return ret; 2278 return ret;
2265} 2279}
2266void MainWindow::quickSyncLocalFile() 2280void MainWindow::quickSyncLocalFile()
2267{ 2281{
2268 //mView->setSyncDevice("local-file" ); 2282 //mView->setSyncDevice("local-file" );
2269 //qDebug("quickSyncLocalFile() "); 2283 //qDebug("quickSyncLocalFile() ");
2270 if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) { 2284 if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) {
2271 // Event* e = mView->getLastSyncEvent(); 2285 // Event* e = mView->getLastSyncEvent();
2272// e->setReadOnly( false ); 2286// e->setReadOnly( false );
2273// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 2287// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2274// e->setReadOnly( true ); 2288// e->setReadOnly( true );
2275 2289
2276 } 2290 }
2277} 2291}
2278 2292
2279void MainWindow::confSync() 2293void MainWindow::confSync()
2280{ 2294{
2281 mView->confSync(); 2295 mView->confSync();
2282 fillSyncMenu(); 2296 fillSyncMenu();
2283} 2297}
2284void MainWindow::syncRemote( KSyncProfile* prof, bool ask) 2298void MainWindow::syncRemote( KSyncProfile* prof, bool ask)
2285{ 2299{
2286 QString question; 2300 QString question;
2287 if ( ask ) { 2301 if ( ask ) {
2288 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 2302 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
2289 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2303 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2290 question, 2304 question,
2291 i18n("Yes"), i18n("No"), 2305 i18n("Yes"), i18n("No"),
2292 0, 0 ) != 0 ) 2306 0, 0 ) != 0 )
2293 return; 2307 return;
2294 } 2308 }
2295 QString command = prof->getPreSyncCommand(); 2309 QString command = prof->getPreSyncCommand();
2296 int fi; 2310 int fi;
2297 if ( (fi = command.find("$PWD$")) > 0 ) { 2311 if ( (fi = command.find("$PWD$")) > 0 ) {
2298 QString pwd = getPassword(); 2312 QString pwd = getPassword();
2299 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2313 command = command.left( fi )+ pwd + command.mid( fi+5 );
2300 2314
2301 } 2315 }
2302 int maxlen = 30; 2316 int maxlen = 30;
2303 if ( QApplication::desktop()->width() > 320 ) 2317 if ( QApplication::desktop()->width() > 320 )
2304 maxlen += 25; 2318 maxlen += 25;
2305 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2319 setCaption ( i18n( "Copy remote file to local machine..." ) );
2306 int fileSize = 0; 2320 int fileSize = 0;
2307 int result = system ( command ); 2321 int result = system ( command );
2308 // 0 : okay 2322 // 0 : okay
2309 // 256: no such file or dir 2323 // 256: no such file or dir
2310 // 2324 //
2311 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2325 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2312 if ( result != 0 ) { 2326 if ( result != 0 ) {
2313 int len = maxlen; 2327 int len = maxlen;
2314 while ( len < command.length() ) { 2328 while ( len < command.length() ) {
2315 command.insert( len , "\n" ); 2329 command.insert( len , "\n" );
2316 len += maxlen +2; 2330 len += maxlen +2;
2317 } 2331 }
2318 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 (command) ; 2332 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 (command) ;
2319 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2333 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2320 question, 2334 question,
2321 i18n("Okay!")) ; 2335 i18n("Okay!")) ;
2322 setCaption ("KO/Pi"); 2336 setCaption ("KO/Pi");
2323 return; 2337 return;
2324 } 2338 }
2325 setCaption ( i18n( "Copying succeed." ) ); 2339 setCaption ( i18n( "Copying succeed." ) );
2326 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 2340 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2327 if ( syncWithFile( prof->getLocalTempFile(), true ) ) { 2341 if ( syncWithFile( prof->getLocalTempFile(), true ) ) {
2328// Event* e = mView->getLastSyncEvent(); 2342// Event* e = mView->getLastSyncEvent();
2329// e->setReadOnly( false ); 2343// e->setReadOnly( false );
2330// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2344// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2331// e->setReadOnly( true ); 2345// e->setReadOnly( true );
2332 if ( KOPrefs::instance()->mWriteBackFile ) { 2346 if ( KOPrefs::instance()->mWriteBackFile ) {
2333 command = prof->getPostSyncCommand(); 2347 command = prof->getPostSyncCommand();
2334 int fi; 2348 int fi;
2335 if ( (fi = command.find("$PWD$")) > 0 ) { 2349 if ( (fi = command.find("$PWD$")) > 0 ) {
2336 QString pwd = getPassword(); 2350 QString pwd = getPassword();
2337 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2351 command = command.left( fi )+ pwd + command.mid( fi+5 );
2338 2352
2339 } 2353 }
2340 setCaption ( i18n( "Writing back file ..." ) ); 2354 setCaption ( i18n( "Writing back file ..." ) );
2341 result = system ( command ); 2355 result = system ( command );
2342 qDebug("KO: Writing back file result: %d ", result); 2356 qDebug("KO: Writing back file result: %d ", result);
2343 if ( result != 0 ) { 2357 if ( result != 0 ) {
2344 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2358 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2345 return; 2359 return;
2346 } else { 2360 } else {
2347 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2361 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2348 } 2362 }
2349 } 2363 }
2350 } 2364 }
2351 return; 2365 return;
2352} 2366}
2353void MainWindow::syncSSH() 2367void MainWindow::syncSSH()
2354{ 2368{
2355 // not used anymore 2369 // not used anymore
2356 QTime timer; 2370 QTime timer;
2357 timer.start(); 2371 timer.start();
2358 //qDebug("MainWindow::syncssh() "); 2372 //qDebug("MainWindow::syncssh() ");
2359 KOPrefs *p = KOPrefs::instance(); 2373 KOPrefs *p = KOPrefs::instance();
2360 QString localFile = p->mLocalTempFile; 2374 QString localFile = p->mLocalTempFile;
2361 QString remoteIP = p->mRemoteIP; 2375 QString remoteIP = p->mRemoteIP;
2362 QString remoteUser = p->mRemoteUser; 2376 QString remoteUser = p->mRemoteUser;
2363 QString remoteFile = p->mRemoteFile; 2377 QString remoteFile = p->mRemoteFile;
2364 if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 ) 2378 if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 )
2365 remoteUser += ":" + p->mRemotePassWd; 2379 remoteUser += ":" + p->mRemotePassWd;
2366 2380
2367 QString question = i18n("Do you really want\nto remote sync?\n \n") + 2381 QString question = i18n("Do you really want\nto remote sync?\n \n") +
2368 i18n("IP: " ) +remoteIP +"\n" + 2382 i18n("IP: " ) +remoteIP +"\n" +
2369 i18n("User: " ) + remoteUser +"\n" ; 2383 i18n("User: " ) + remoteUser +"\n" ;
2370 int maxlen = 30; 2384 int maxlen = 30;
2371 if ( QApplication::desktop()->width() > 320 ) 2385 if ( QApplication::desktop()->width() > 320 )
2372 maxlen += 25; 2386 maxlen += 25;
2373 if ( remoteFile.length() > maxlen ) 2387 if ( remoteFile.length() > maxlen )
2374 question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n"; 2388 question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n";
2375 else 2389 else
2376 question += i18n("Remote file:\n " ) + remoteFile +"\n"; 2390 question += i18n("Remote file:\n " ) + remoteFile +"\n";
2377 if ( localFile.length() > maxlen ) 2391 if ( localFile.length() > maxlen )
2378 question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n"; 2392 question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n";
2379 else 2393 else
2380 question += i18n("Local temp file:\n " ) + localFile +"\n"; 2394 question += i18n("Local temp file:\n " ) + localFile +"\n";
2381 2395
2382 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2396 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2383 question, 2397 question,
2384 i18n("Yes"), i18n("No"), 2398 i18n("Yes"), i18n("No"),
2385 0, 0 ) != 0 ) 2399 0, 0 ) != 0 )
2386 return; 2400 return;
2387 // if ( !p->mUsePassWd ) { 2401 // if ( !p->mUsePassWd ) {
2388 // QString pass = getPassword(); 2402 // QString pass = getPassword();
2389 // if ( pass.length() > 0 ) 2403 // if ( pass.length() > 0 )
2390 // remoteUser += ":" + pass; 2404 // remoteUser += ":" + pass;
2391 // } 2405 // }
2392 QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile; 2406 QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile;
2393 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2407 setCaption ( i18n( "Copy remote file to local machine..." ) );
2394 int fileSize = 0; 2408 int fileSize = 0;
2395 int result = system ( command ); 2409 int result = system ( command );
2396 // 0 : okay 2410 // 0 : okay
2397 // 256: no such file or dir 2411 // 256: no such file or dir
2398 // 2412 //
2399 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2413 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2400 if ( result != 0 ) { 2414 if ( result != 0 ) {
2401 int len = maxlen; 2415 int len = maxlen;
2402 while ( len < command.length() ) { 2416 while ( len < command.length() ) {
2403 command.insert( len , "\n" ); 2417 command.insert( len , "\n" );
2404 len += maxlen +2; 2418 len += maxlen +2;
2405 } 2419 }
2406 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 (command) ; 2420 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 (command) ;
2407 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2421 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2408 question, 2422 question,
2409 i18n("Okay!")) ; 2423 i18n("Okay!")) ;
2410 setCaption ("KO/Pi"); 2424 setCaption ("KO/Pi");
2411 return; 2425 return;
2412 } 2426 }
2413 2427
2414 2428
2415 setCaption ( i18n( "Copying succeed." ) ); 2429 setCaption ( i18n( "Copying succeed." ) );
2416 //mView->setSyncDevice("ssh-scp" ); 2430 //mView->setSyncDevice("ssh-scp" );
2417 if ( syncWithFile(localFile , true ) ) { 2431 if ( syncWithFile(localFile , true ) ) {
2418// Event* e = mView->getLastSyncEvent(); 2432// Event* e = mView->getLastSyncEvent();
2419// e->setReadOnly( false ); 2433// e->setReadOnly( false );
2420// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2434// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2421// e->setReadOnly( true ); 2435// e->setReadOnly( true );
2422 if ( KOPrefs::instance()->mWriteBackFile ) { 2436 if ( KOPrefs::instance()->mWriteBackFile ) {
2423 command = "scp " + localFile +" " +remoteUser + "@" + remoteIP +":" + remoteFile ; 2437 command = "scp " + localFile +" " +remoteUser + "@" + remoteIP +":" + remoteFile ;
2424 setCaption ( i18n( "Writing back file ..." ) ); 2438 setCaption ( i18n( "Writing back file ..." ) );
2425 result = system ( command ); 2439 result = system ( command );
2426 if ( result != 0 ) { 2440 if ( result != 0 ) {
2427 int len = maxlen; 2441 int len = maxlen;
2428 while ( len < command.length() ) { 2442 while ( len < command.length() ) {
2429 command.insert( len , "\n" ); 2443 command.insert( len , "\n" );
2430 len += maxlen +2; 2444 len += maxlen +2;
2431 } 2445 }
2432 question = i18n("Sorry, the copy back command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; 2446 question = i18n("Sorry, the copy back command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ;
2433 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2447 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2434 question, 2448 question,
2435 i18n("Okay!")) ; 2449 i18n("Okay!")) ;
2436 setCaption ("KO/Pi"); 2450 setCaption ("KO/Pi");
2437 return; 2451 return;
2438 } else { 2452 } else {
2439 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2453 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2440 } 2454 }
2441 } 2455 }
2442 } 2456 }
2443 return; 2457 return;
2444#if 0 2458#if 0
2445 system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics"); 2459 system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics");
2446 while ( timer.elapsed() < 5000 ) 2460 while ( timer.elapsed() < 5000 )
2447 qApp->processEvents(); 2461 qApp->processEvents();
2448 2462
2449 qDebug("MainWindow::merging) "); 2463 qDebug("MainWindow::merging) ");
2450 mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 ); 2464 mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 );
2451 while ( mBlockSaveFlag ) 2465 while ( mBlockSaveFlag )
2452 qApp->processEvents(); 2466 qApp->processEvents();
2453 save(); 2467 save();
2454 system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics"); 2468 system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics");
2455#endif 2469#endif
2456 2470
2457} 2471}
2458 2472
2459 2473
2460void MainWindow::syncSharp() 2474void MainWindow::syncSharp()
2461{ 2475{
2462 if ( mCalendarModifiedFlag ) 2476 if ( mCalendarModifiedFlag )
2463 save(); 2477 save();
2464 mView->syncSharp(); 2478 mView->syncSharp();
2465 slotModifiedChanged( true ); 2479 slotModifiedChanged( true );
2466 2480
2467} 2481}
2468void MainWindow::syncPhone() 2482void MainWindow::syncPhone()
2469{ 2483{
2470 if ( mCalendarModifiedFlag ) 2484 if ( mCalendarModifiedFlag )
2471 save(); 2485 save();
2472 mView->syncPhone(); 2486 mView->syncPhone();
2473 slotModifiedChanged( true ); 2487 slotModifiedChanged( true );
2474 2488
2475} 2489}
2476 2490
2477void MainWindow::printSel( ) 2491void MainWindow::printSel( )
2478{ 2492{
2479 mView->viewManager()->agendaView()->agenda()->printSelection(); 2493 mView->viewManager()->agendaView()->agenda()->printSelection();
2480} 2494}
2481 2495
2482void MainWindow::printCal() 2496void MainWindow::printCal()
2483{ 2497{
2484 mView->print();//mCp->showDialog(); 2498 mView->print();//mCp->showDialog();
2485} 2499}
2486 2500
2487 2501
2488 2502
2489KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 2503KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
2490{ 2504{
2491 mPassWord = pw; 2505 mPassWord = pw;
2492 mSocket = 0; 2506 mSocket = 0;
2507 mSyncActionDialog = 0;
2493}; 2508};
2494 2509
2495void KServerSocket::newConnection ( int socket ) 2510void KServerSocket::newConnection ( int socket )
2496{ 2511{
2497 qDebug("KServerSocket:New connection %d ", socket); 2512 qDebug("KServerSocket:New connection %d ", socket);
2498 if ( mSocket ) { 2513 if ( mSocket ) {
2499 qDebug("KServerSocket::newConnection Socket deleted! "); 2514 qDebug("KServerSocket::newConnection Socket deleted! ");
2500 delete mSocket; 2515 delete mSocket;
2501 mSocket = 0; 2516 mSocket = 0;
2502 } 2517 }
2503 mSocket = new QSocket( this ); 2518 mSocket = new QSocket( this );
2504 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 2519 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
2505 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 2520 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
2506 mSocket->setSocket( socket ); 2521 mSocket->setSocket( socket );
2507} 2522}
2508 2523
2509void KServerSocket::discardClient() 2524void KServerSocket::discardClient()
2510{ 2525{
2511 qDebug(" KServerSocket::discardClient()"); 2526 qDebug(" KServerSocket::discardClient()");
2512 if ( mSocket ) { 2527 if ( mSocket ) {
2513 qDebug("delete "); 2528 qDebug("delete ");
2514 delete mSocket; 2529 delete mSocket;
2515 mSocket = 0; 2530 mSocket = 0;
2516 } 2531 }
2517 //emit endConnect(); 2532 //emit endConnect();
2518} 2533}
2519void KServerSocket::readClient() 2534void KServerSocket::readClient()
2520{ 2535{
2521 if ( mSocket == 0 ) { 2536 if ( mSocket == 0 ) {
2522 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 2537 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
2523 return; 2538 return;
2524 } 2539 }
2525 qDebug("KServerSocket readClient()"); 2540 qDebug("KServerSocket readClient()");
2526 if ( mSocket->canReadLine() ) { 2541 if ( mSocket->canReadLine() ) {
2527 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); 2542 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() );
2528 qDebug("KServerSocket socket->canReadLine()"); 2543 qDebug("KServerSocket socket->canReadLine()");
2529 if ( tokens[0] == "GET" ) { 2544 if ( tokens[0] == "GET" ) {
2530 if ( tokens[1] == mPassWord ) 2545 if ( tokens[1] == mPassWord )
2531 emit sendFile( mSocket ); 2546 //emit sendFile( mSocket );
2547 send_file();
2532 else { 2548 else {
2533 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); 2549 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password"));
2534 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 2550 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
2535 } 2551 }
2536 } 2552 }
2537 if ( tokens[0] == "PUT" ) { 2553 if ( tokens[0] == "PUT" ) {
2538 if ( tokens[1] == mPassWord ) 2554 if ( tokens[1] == mPassWord )
2539 emit getFile( mSocket ); 2555 //emit getFile( mSocket );
2556 get_file();
2540 else { 2557 else {
2541 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); 2558 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password"));
2542 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 2559 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
2543 } 2560 }
2544 } 2561 }
2545 if ( tokens[0] == "STOP" ) { 2562 if ( tokens[0] == "STOP" ) {
2546 emit endConnect(); 2563 emit endConnect();
2547 } 2564 }
2548 } 2565 }
2549} 2566}
2550 2567
2568void KServerSocket::send_file()
2569{
2570 qDebug("MainWindow::sendFile(QSocket* s) ");
2571 if ( mSyncActionDialog )
2572 delete mSyncActionDialog;
2573 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
2574 mSyncActionDialog->setCaption(i18n("Received sync request"));
2575 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use this application!\n\nIf syncing fails you can close this dialog."), mSyncActionDialog );
2576 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
2577 lay->addWidget( label);
2578 lay->setMargin(7);
2579 lay->setSpacing(7);
2580 mSyncActionDialog->setFixedSize( 230, 120);
2581 mSyncActionDialog->show();
2582 qDebug("KSS::saving ... ");
2583 emit saveFile();
2584 qApp->processEvents();
2585 QString fileName = mFileName;
2586 QFile file( fileName );
2587 if (!file.open( IO_ReadOnly ) ) {
2588 delete mSyncActionDialog;
2589 mSyncActionDialog = 0;
2590 qDebug("KSS::error open file ");
2591 mSocket->close();
2592 if ( mSocket->state() == QSocket::Idle )
2593 QTimer::singleShot( 10, this , SLOT ( discardClient()));
2594 return ;
2595
2596 }
2597 mSyncActionDialog->setCaption( i18n("Sending file...") );
2598 QTextStream ts( &file );
2599 ts.setCodec( QTextCodec::codecForName("utf8") );
2600 QTextStream os( mSocket );
2601 os.setCodec( QTextCodec::codecForName("utf8") );
2602 //os.setEncoding( QTextStream::UnicodeUTF8 );
2603 while ( ! ts.atEnd() ) {
2604 os << ts.readLine() << "\n";
2605 }
2606 //os << ts.read();
2607 file.close();
2608 mSyncActionDialog->setCaption( i18n("Waiting to get back synced file") );
2609 qDebug("file sent ");
2610 mSocket->close();
2611 if ( mSocket->state() == QSocket::Idle )
2612 QTimer::singleShot( 10, this , SLOT ( discardClient()));
2613}
2614void KServerSocket::get_file()
2615{
2616 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
2617
2618 piTime.start();
2619 piFileString = "";
2620 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
2621}
2622
2623
2624void KServerSocket::readBackFileFromSocket()
2625{
2626 qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
2627 while ( mSocket->canReadLine () ) {
2628 piTime.restart();
2629 QString line = mSocket->readLine ();
2630 piFileString += line;
2631 qDebug("readline: %s ", line.latin1());
2632 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
2633
2634 }
2635 if ( piTime.elapsed () < 3000 ) {
2636 // wait for more
2637 qDebug("waitformore ");
2638 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
2639 return;
2640 }
2641 QString fileName = mFileName;
2642 QFile file ( fileName );
2643 if (!file.open( IO_WriteOnly ) ) {
2644 delete mSyncActionDialog;
2645 mSyncActionDialog = 0;
2646 qDebug("error open cal file ");
2647 piFileString = "";
2648 emit file_received( false );
2649 return ;
2650
2651 }
2652
2653 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
2654 QTextStream ts ( &file );
2655 ts.setCodec( QTextCodec::codecForName("utf8") );
2656 qDebug("finish ");
2657 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
2658 ts << piFileString;
2659 mSocket->close();
2660 if ( mSocket->state() == QSocket::Idle )
2661 QTimer::singleShot( 10, this , SLOT ( discardClient()));
2662 file.close();
2663 delete mSyncActionDialog;
2664 mSyncActionDialog = 0;
2665 piFileString = "";
2666 emit file_received( true );
2667
2668}
2669
2551KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 2670KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
2552{ 2671{
2553 mPassWord = password; 2672 mPassWord = password;
2554 mSocket = 0; 2673 mSocket = 0;
2555 mPort = port; 2674 mPort = port;
2556 mHost = host; 2675 mHost = host;
2557 2676
2558 mRetVal = false; 2677 mRetVal = false;
2559 mTimerSocket = new QTimer ( this ); 2678 mTimerSocket = new QTimer ( this );
2560 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 2679 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
2561} 2680}
2562void KCommandSocket::readFile( QString fn ) 2681void KCommandSocket::readFile( QString fn )
2563{ 2682{
2564 if ( !mSocket ) { 2683 if ( !mSocket ) {
2565 mSocket = new QSocket( this ); 2684 mSocket = new QSocket( this );
2566 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 2685 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
2567 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 2686 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2568 } 2687 }
2569 mFileString = ""; 2688 mFileString = "";
2570 mFileName = fn; 2689 mFileName = fn;
2571 mFirst = true; 2690 mFirst = true;
2572 mSocket->connectToHost( mHost, mPort ); 2691 mSocket->connectToHost( mHost, mPort );
2573 QTextStream os( mSocket ); 2692 QTextStream os( mSocket );
2574 os.setEncoding( QTextStream::UnicodeUTF8 ); 2693 os.setEncoding( QTextStream::UnicodeUTF8 );
2575 os << "GET " << mPassWord << "\r\n"; 2694 os << "GET " << mPassWord << "\r\n";
2576 mTimerSocket->start( 10000 ); 2695 mTimerSocket->start( 10000 );
2577} 2696}
2578 2697
2579void KCommandSocket::writeFile( QString ) 2698void KCommandSocket::writeFile( QString )
2580{ 2699{
2581 2700
2582} 2701}
2583void KCommandSocket::startReadFileFromSocket() 2702void KCommandSocket::startReadFileFromSocket()
2584{ 2703{
2585 if ( ! mFirst ) 2704 if ( ! mFirst )
2586 return; 2705 return;
2587 mFirst = false; 2706 mFirst = false;
2588 mTimerSocket->stop(); 2707 mTimerSocket->stop();
2589 mFileString = ""; 2708 mFileString = "";
2590 mTime.start(); 2709 mTime.start();
2591 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 2710 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
2592 2711
2593} 2712}
2594void KCommandSocket::readFileFromSocket() 2713void KCommandSocket::readFileFromSocket()
2595{ 2714{
2596 qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 2715 qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
2597 while ( mSocket->canReadLine () ) { 2716 while ( mSocket->canReadLine () ) {
2598 mTime.restart(); 2717 mTime.restart();
2599 QString line = mSocket->readLine (); 2718 QString line = mSocket->readLine ();
2600 mFileString += line; 2719 mFileString += line;
2601 qDebug("readline: %s ", line.latin1()); 2720 qDebug("readline: %s ", line.latin1());
2602 } 2721 }
2603 if ( mTime.elapsed () < 3000 ) { 2722 if ( mTime.elapsed () < 3000 ) {
2604 // wait for more 2723 // wait for more
2605 qDebug("waitformore "); 2724 qDebug("waitformore ");
2606 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 2725 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
2607 return; 2726 return;
2608 } 2727 }
2609 QString fileName = mFileName; 2728 QString fileName = mFileName;
2610 QFile file ( fileName ); 2729 QFile file ( fileName );
2611 if (!file.open( IO_WriteOnly ) ) { 2730 if (!file.open( IO_WriteOnly ) ) {
2612 mFileString = ""; 2731 mFileString = "";
2613 mRetVal = false; 2732 mRetVal = false;
2614 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 2733 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
2615 deleteSocket(); 2734 deleteSocket();
2616 return ; 2735 return ;
2617 2736
2618 } 2737 }
2619 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 2738 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
2620 QTextStream ts ( &file ); 2739 QTextStream ts ( &file );
2621 ts.setCodec( QTextCodec::codecForName("utf8") ); 2740 ts.setCodec( QTextCodec::codecForName("utf8") );
2622 qDebug("finish "); 2741 qDebug("finish ");
2623 ts << mFileString; 2742 ts << mFileString;
2624 file.close(); 2743 file.close();
2625 mFileString = ""; 2744 mFileString = "";
2626 mRetVal = true; 2745 mRetVal = true;
2627 mSocket->close(); 2746 mSocket->close();
2628 // if state is not idle, deleteSocket(); is called via 2747 // if state is not idle, deleteSocket(); is called via
2629 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 2748 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2630 if ( mSocket->state() == QSocket::Idle ) 2749 if ( mSocket->state() == QSocket::Idle )
2631 deleteSocket(); 2750 deleteSocket();
2632} 2751}
2633 2752
2634void KCommandSocket::deleteSocket() 2753void KCommandSocket::deleteSocket()
2635{ 2754{
2636 if ( !mSocket) 2755 if ( !mSocket)
2637 return; 2756 return;
2638 if ( mTimerSocket->isActive () ) { 2757 if ( mTimerSocket->isActive () ) {
2639 mTimerSocket->stop(); 2758 mTimerSocket->stop();
2640 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out ")); 2759 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
2641 mRetVal = false; 2760 mRetVal = false;
2642 } 2761 }
2643 qDebug("KCommandSocket::deleteSocket() %d", mRetVal); 2762 qDebug("KCommandSocket::deleteSocket() %d", mRetVal);
2644 delete mSocket; 2763 delete mSocket;
2645 mSocket = 0; 2764 mSocket = 0;
2646 emit commandFinished( mRetVal ); 2765 emit commandFinished( mRetVal );
2647} 2766}
2648 2767
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 11a816c..8b76067 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -1,201 +1,212 @@
1#ifndef KORGE_MAINWINDOW_H 1#ifndef KORGE_MAINWINDOW_H
2#define KORGE_MAINWINDOW_H 2#define KORGE_MAINWINDOW_H
3 3
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5#include <qtimer.h> 5#include <qtimer.h>
6#include <qdict.h> 6#include <qdict.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qsocket.h> 8#include <qsocket.h>
9#include <qtextstream.h> 9#include <qtextstream.h>
10#include <qregexp.h> 10#include <qregexp.h>
11 11
12#include <libkcal/incidence.h> 12#include <libkcal/incidence.h>
13#include "simplealarmclient.h" 13#include "simplealarmclient.h"
14 14
15class QAction; 15class QAction;
16class CalendarView; 16class CalendarView;
17class KSyncProfile; 17class KSyncProfile;
18#ifdef DESKTOP_VERSION 18#ifdef DESKTOP_VERSION
19 19
20#define QPEToolBar QToolBar 20#define QPEToolBar QToolBar
21#define QPEMenuBar QMenuBar 21#define QPEMenuBar QMenuBar
22#endif 22#endif
23class QPEToolBar; 23class QPEToolBar;
24#include <qserversocket.h> 24#include <qserversocket.h>
25#include <qsocket.h> 25#include <qsocket.h>
26#include <qnetworkprotocol.h> 26#include <qnetworkprotocol.h>
27 27
28class KServerSocket : public QServerSocket 28class KServerSocket : public QServerSocket
29{ 29{
30 Q_OBJECT 30 Q_OBJECT
31 31
32public: 32public:
33 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); 33 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
34 34
35 void newConnection ( int socket ) ; 35 void newConnection ( int socket ) ;
36 void setFileName( QString fn ) {mFileName = fn;};
36 37
37signals: 38signals:
38 void sendFile(QSocket*); 39 //void sendFile(QSocket*);
39 void getFile(QSocket*); 40 //void getFile(QSocket*);
41 void file_received( bool );
42 //void file_sent();
43 void saveFile();
40 void endConnect(); 44 void endConnect();
41private slots: 45private slots:
42 void discardClient(); 46 void discardClient();
43 void readClient(); 47 void readClient();
48 void readBackFileFromSocket();
44 private : 49 private :
50 void send_file();
51 void get_file();
52 QDialog* mSyncActionDialog;
45 QSocket* mSocket; 53 QSocket* mSocket;
46 QString mPassWord; 54 QString mPassWord;
55 QString mFileName;
56 QTime piTime;
57 QString piFileString;
47}; 58};
48 59
49class KCommandSocket : public QObject 60class KCommandSocket : public QObject
50{ 61{
51 Q_OBJECT 62 Q_OBJECT
52 63
53public: 64public:
54 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 65 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
55 void readFile( QString ); 66 void readFile( QString );
56 void writeFile( QString ); 67 void writeFile( QString );
57 68
58 69
59signals: 70signals:
60 void commandFinished( bool ); 71 void commandFinished( bool );
61private slots: 72private slots:
62 void startReadFileFromSocket(); 73 void startReadFileFromSocket();
63 void readFileFromSocket(); 74 void readFileFromSocket();
64 void deleteSocket(); 75 void deleteSocket();
65 private : 76 private :
66 QSocket* mSocket; 77 QSocket* mSocket;
67 QString mPassWord; 78 QString mPassWord;
68 Q_UINT16 mPort; 79 Q_UINT16 mPort;
69 QString mHost; 80 QString mHost;
70 QString mFileName; 81 QString mFileName;
71 QTimer* mTimerSocket; 82 QTimer* mTimerSocket;
72 bool mRetVal; 83 bool mRetVal;
73 QTime mTime; 84 QTime mTime;
74 QString mFileString; 85 QString mFileString;
75 bool mFirst; 86 bool mFirst;
76}; 87};
77 88
78namespace KCal { 89namespace KCal {
79class CalendarLocal; 90class CalendarLocal;
80} 91}
81 92
82using namespace KCal; 93using namespace KCal;
83 94
84class MainWindow : public QMainWindow 95class MainWindow : public QMainWindow
85{ 96{
86 Q_OBJECT 97 Q_OBJECT
87 public: 98 public:
88 MainWindow( QWidget *parent = 0, const char *name = 0, QString command = ""); 99 MainWindow( QWidget *parent = 0, const char *name = 0, QString command = "");
89 ~MainWindow(); 100 ~MainWindow();
90 public slots: 101 public slots:
91 virtual void showMaximized (); 102 virtual void showMaximized ();
92 void configureAgenda( int ); 103 void configureAgenda( int );
93 void recieve( const QCString& msg, const QByteArray& data ); 104 void recieve( const QCString& msg, const QByteArray& data );
94 static QString defaultFileName(); 105 static QString defaultFileName();
95 static QString resourcePath(); 106 static QString resourcePath();
96 protected slots: 107 protected slots:
97 void setCaptionToDates(); 108 void setCaptionToDates();
98 int ringSync(); 109 int ringSync();
99 void multiSync( bool askforPrefs = false ); 110 void multiSync( bool askforPrefs = false );
100 void about(); 111 void about();
101 void licence(); 112 void licence();
102 void faq(); 113 void faq();
103 void usertrans(); 114 void usertrans();
104 void features(); 115 void features();
105 void synchowto(); 116 void synchowto();
106 void whatsNew(); 117 void whatsNew();
107 void keyBindings(); 118 void keyBindings();
108 void aboutAutoSaving();; 119 void aboutAutoSaving();;
109 void aboutKnownBugs(); 120 void aboutKnownBugs();
110 121
111 void processIncidenceSelection( Incidence * ); 122 void processIncidenceSelection( Incidence * );
112 123
113 void importQtopia(); 124 void importQtopia();
114 void importBday(); 125 void importBday();
115 void importOL(); 126 void importOL();
116 void importIcal(); 127 void importIcal();
117 void importFile( QString, bool ); 128 void importFile( QString, bool );
118 void quickImportIcal(); 129 void quickImportIcal();
119 130
120 void slotModifiedChanged( bool ); 131 void slotModifiedChanged( bool );
121 132
122 void save(); 133 void save();
123 void configureToolBar( int ); 134 void configureToolBar( int );
124 void printSel(); 135 void printSel();
125 void printCal(); 136 void printCal();
126 void saveCalendar(); 137 void saveCalendar();
127 void loadCalendar(); 138 void loadCalendar();
128 void exportVCalendar(); 139 void exportVCalendar();
129 void fillFilterMenu(); 140 void fillFilterMenu();
130 void selectFilter( int ); 141 void selectFilter( int );
131 142
132 void slotSyncMenu( int ); 143 void slotSyncMenu( int );
133 void syncSSH(); 144 void syncSSH();
134 void confSync(); 145 void confSync();
135 void syncSharp(); 146 void syncSharp();
136 void syncPhone(); 147 void syncPhone();
137 void syncLocalFile(); 148 void syncLocalFile();
138 bool syncWithFile( QString, bool ); 149 bool syncWithFile( QString, bool );
139 void quickSyncLocalFile(); 150 void quickSyncLocalFile();
140 151
141 152
142 protected: 153 protected:
143 void displayText( QString, QString); 154 void displayText( QString, QString);
144 void displayFile( QString, QString); 155 void displayFile( QString, QString);
145 156
146 void enableIncidenceActions( bool ); 157 void enableIncidenceActions( bool );
147 158
148 private slots: 159 private slots:
149 QSocket* piSocket; 160 QSocket* piSocket;
150 QString piFileString; 161 QString piFileString;
151 QTime piTime; 162 QTime piTime;
152 void deleteCommandSocket(bool); 163 void deleteCommandSocket(bool);
153 void deleteCommandSocketFinish(); 164 void deleteCommandSocketFinish();
154 void fillSyncMenu(); 165 void fillSyncMenu();
155 void sendFile(QSocket* s); 166 void sendFile(QSocket* s);
156 void getFile(QSocket* socket); 167 void getFile( bool );
157 void readFileFromSocket(); 168 void readFileFromSocket();
158 void readBackFileFromSocket(); 169 void readBackFileFromSocket();
159 void endConnect(); 170 void endConnect();
160 private: 171 private:
161 //QTimer* mTimerCommandSocket; 172 //QTimer* mTimerCommandSocket;
162 QString mPassWordPiSync; 173 QString mPassWordPiSync;
163 KCommandSocket* mCommandSocket; 174 KCommandSocket* mCommandSocket;
164 QSocket* mCommandSocketFinish; 175 QSocket* mCommandSocketFinish;
165 KServerSocket * mServerSocket; 176 KServerSocket * mServerSocket;
166 bool mClosed; 177 bool mClosed;
167 void saveOnClose(); 178 void saveOnClose();
168 int mCurrentSyncProfile; 179 int mCurrentSyncProfile;
169 void enableQuick(); 180 void enableQuick();
170 void performQuick(); 181 void performQuick();
171 void performQuickQuick(); 182 void performQuickQuick();
172 void syncRemote( KSyncProfile* , bool ask = true); 183 void syncRemote( KSyncProfile* , bool ask = true);
173 bool mFlagKeyPressed; 184 bool mFlagKeyPressed;
174 bool mBlockAtStartup; 185 bool mBlockAtStartup;
175 QPEToolBar *iconToolBar; 186 QPEToolBar *iconToolBar;
176 void initActions(); 187 void initActions();
177 void setDefaultPreferences(); 188 void setDefaultPreferences();
178 void keyPressEvent ( QKeyEvent * ) ; 189 void keyPressEvent ( QKeyEvent * ) ;
179 void keyReleaseEvent ( QKeyEvent * ) ; 190 void keyReleaseEvent ( QKeyEvent * ) ;
180 QPopupMenu *configureToolBarMenu; 191 QPopupMenu *configureToolBarMenu;
181 QPopupMenu *selectFilterMenu; 192 QPopupMenu *selectFilterMenu;
182 QPopupMenu *configureAgendaMenu, *syncMenu; 193 QPopupMenu *configureAgendaMenu, *syncMenu;
183 CalendarLocal *mCalendar; 194 CalendarLocal *mCalendar;
184 CalendarView *mView; 195 CalendarView *mView;
185 QString getPassword(); 196 QString getPassword();
186 QAction *mNewSubTodoAction; 197 QAction *mNewSubTodoAction;
187 198
188 QAction *mShowAction; 199 QAction *mShowAction;
189 QAction *mEditAction; 200 QAction *mEditAction;
190 QAction *mDeleteAction; 201 QAction *mDeleteAction;
191 void closeEvent( QCloseEvent* ce ); 202 void closeEvent( QCloseEvent* ce );
192 SimpleAlarmClient mAlarmClient; 203 SimpleAlarmClient mAlarmClient;
193 QTimer mSaveTimer; 204 QTimer mSaveTimer;
194 bool mBlockSaveFlag; 205 bool mBlockSaveFlag;
195 bool mCalendarModifiedFlag; 206 bool mCalendarModifiedFlag;
196 QPixmap loadPixmap( QString ); 207 QPixmap loadPixmap( QString );
197 QDialog * mSyncActionDialog; 208 QDialog * mSyncActionDialog;
198}; 209};
199 210
200 211
201#endif 212#endif