summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-07-10 20:17:14 (UTC)
committer zautrix <zautrix>2005-07-10 20:17:14 (UTC)
commitbf95dce0b9143e3c9b9aeb3cdfda24cb5325dd33 (patch) (unidiff)
tree19849ae249cb104db250d6e60e60de4ffef0acbc
parentf06311e58cb5887fd673eb1c2c48acf7cd987ad9 (diff)
downloadkdepimpi-bf95dce0b9143e3c9b9aeb3cdfda24cb5325dd33.zip
kdepimpi-bf95dce0b9143e3c9b9aeb3cdfda24cb5325dd33.tar.gz
kdepimpi-bf95dce0b9143e3c9b9aeb3cdfda24cb5325dd33.tar.bz2
fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 427d71b..9674921 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1755,2049 +1755,2053 @@ void CalendarView::syncExternal( int mode )
1755 return; 1755 return;
1756 } 1756 }
1757 if ( loadSuccess ) { 1757 if ( loadSuccess ) {
1758 getEventViewerDialog()->setSyncMode( true ); 1758 getEventViewerDialog()->setSyncMode( true );
1759 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1759 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1760 getEventViewerDialog()->setSyncMode( false ); 1760 getEventViewerDialog()->setSyncMode( false );
1761 qApp->processEvents(); 1761 qApp->processEvents();
1762 if ( syncOK ) { 1762 if ( syncOK ) {
1763 if ( mSyncManager->mWriteBackFile ) 1763 if ( mSyncManager->mWriteBackFile )
1764 { 1764 {
1765 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1765 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1766 Incidence* inc = iL.first(); 1766 Incidence* inc = iL.first();
1767 if ( phoneFormat ) { 1767 if ( phoneFormat ) {
1768 while ( inc ) { 1768 while ( inc ) {
1769 inc->removeID(mCurrentSyncDevice); 1769 inc->removeID(mCurrentSyncDevice);
1770 inc = iL.next(); 1770 inc = iL.next();
1771 } 1771 }
1772 } 1772 }
1773#ifndef DESKTOP_VERSION 1773#ifndef DESKTOP_VERSION
1774 if ( sharpFormat ) 1774 if ( sharpFormat )
1775 sharpFormat->save(calendar); 1775 sharpFormat->save(calendar);
1776#endif 1776#endif
1777 if ( phoneFormat ) 1777 if ( phoneFormat )
1778 phoneFormat->save(calendar); 1778 phoneFormat->save(calendar);
1779 iL = calendar->rawIncidences(); 1779 iL = calendar->rawIncidences();
1780 inc = iL.first(); 1780 inc = iL.first();
1781 Incidence* loc; 1781 Incidence* loc;
1782 while ( inc ) { 1782 while ( inc ) {
1783 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1783 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1784 loc = mCalendar->incidence(inc->uid() ); 1784 loc = mCalendar->incidence(inc->uid() );
1785 if ( loc ) { 1785 if ( loc ) {
1786 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1786 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1787 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1787 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1788 } 1788 }
1789 } 1789 }
1790 inc = iL.next(); 1790 inc = iL.next();
1791 } 1791 }
1792 Incidence* lse = getLastSyncEvent(); 1792 Incidence* lse = getLastSyncEvent();
1793 if ( lse ) { 1793 if ( lse ) {
1794 lse->setReadOnly( false ); 1794 lse->setReadOnly( false );
1795 lse->setDescription( "" ); 1795 lse->setDescription( "" );
1796 lse->setReadOnly( true ); 1796 lse->setReadOnly( true );
1797 } 1797 }
1798 } 1798 }
1799 } else { 1799 } else {
1800 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1800 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1801 } 1801 }
1802 setModified( true ); 1802 setModified( true );
1803 } else { 1803 } else {
1804 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1804 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1805 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1805 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1806 question, i18n("Ok")) ; 1806 question, i18n("Ok")) ;
1807 1807
1808 } 1808 }
1809 delete calendar; 1809 delete calendar;
1810 updateView(); 1810 updateView();
1811 emit tempDisableBR(false); 1811 emit tempDisableBR(false);
1812 return ;//syncOK; 1812 return ;//syncOK;
1813 1813
1814} 1814}
1815 1815
1816bool CalendarView::importBday() 1816bool CalendarView::importBday()
1817{ 1817{
1818#ifndef KORG_NOKABC 1818#ifndef KORG_NOKABC
1819 1819
1820#ifdef DESKTOP_VERSION 1820#ifdef DESKTOP_VERSION
1821 int curCal = mCalendar->defaultCalendar(); 1821 int curCal = mCalendar->defaultCalendar();
1822 int bd = mCalEditView->getBirtdayID(); 1822 int bd = mCalEditView->getBirtdayID();
1823 if ( bd == 0 ) 1823 if ( bd == 0 )
1824 return false; 1824 return false;
1825 mCalendar->setDefaultCalendar( bd ); 1825 mCalendar->setDefaultCalendar( bd );
1826 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1826 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1827 KABC::AddressBook::Iterator it; 1827 KABC::AddressBook::Iterator it;
1828 int count = 0; 1828 int count = 0;
1829 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1829 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1830 ++count; 1830 ++count;
1831 } 1831 }
1832 QProgressBar bar(count,0 ); 1832 QProgressBar bar(count,0 );
1833 int w = 300; 1833 int w = 300;
1834 if ( QApplication::desktop()->width() < 320 ) 1834 if ( QApplication::desktop()->width() < 320 )
1835 w = 220; 1835 w = 220;
1836 int h = bar.sizeHint().height() ; 1836 int h = bar.sizeHint().height() ;
1837 int dw = QApplication::desktop()->width(); 1837 int dw = QApplication::desktop()->width();
1838 int dh = QApplication::desktop()->height(); 1838 int dh = QApplication::desktop()->height();
1839 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1839 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1840 bar.show(); 1840 bar.show();
1841 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1841 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1842 qApp->processEvents(); 1842 qApp->processEvents();
1843 count = 0; 1843 count = 0;
1844 int addCount = 0; 1844 int addCount = 0;
1845 KCal::Attendee* a = 0; 1845 KCal::Attendee* a = 0;
1846 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1846 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1847 if ( ! bar.isVisible() ) 1847 if ( ! bar.isVisible() )
1848 return false; 1848 return false;
1849 bar.setProgress( count++ ); 1849 bar.setProgress( count++ );
1850 qApp->processEvents(); 1850 qApp->processEvents();
1851 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1851 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1852 if ( (*it).birthday().date().isValid() ){ 1852 if ( (*it).birthday().date().isValid() ){
1853 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1853 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1854 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1854 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1855 ++addCount; 1855 ++addCount;
1856 } 1856 }
1857 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1857 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1858 if ( anni.isValid() ){ 1858 if ( anni.isValid() ){
1859 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1859 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1860 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1860 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1861 ++addCount; 1861 ++addCount;
1862 } 1862 }
1863 } 1863 }
1864 mCalendar->setDefaultCalendar( curCal ); 1864 mCalendar->setDefaultCalendar( curCal );
1865 updateView(); 1865 updateView();
1866 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1866 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1867#else //DESKTOP_VERSION 1867#else //DESKTOP_VERSION
1868 1868
1869 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1869 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1870 // the result should now arrive through method insertBirthdays 1870 // the result should now arrive through method insertBirthdays
1871 1871
1872#endif //DESKTOP_VERSION 1872#endif //DESKTOP_VERSION
1873 1873
1874#endif //KORG_NOKABC 1874#endif //KORG_NOKABC
1875 1875
1876 1876
1877 return true; 1877 return true;
1878} 1878}
1879 1879
1880// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1880// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1881void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1881void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1882 const QStringList& anniversaryList, const QStringList& realNameList, 1882 const QStringList& anniversaryList, const QStringList& realNameList,
1883 const QStringList& emailList, const QStringList& assembledNameList, 1883 const QStringList& emailList, const QStringList& assembledNameList,
1884 const QStringList& uidList) 1884 const QStringList& uidList)
1885{ 1885{
1886 1886
1887 //qDebug("KO::CalendarView::insertBirthdays"); 1887 //qDebug("KO::CalendarView::insertBirthdays");
1888 if (uid == this->name()) 1888 if (uid == this->name())
1889 { 1889 {
1890 int curCal = mCalendar->defaultCalendar(); 1890 int curCal = mCalendar->defaultCalendar();
1891 int bd = mCalEditView->getBirtdayID(); 1891 int bd = mCalEditView->getBirtdayID();
1892 if ( bd == 0 ) 1892 if ( bd == 0 )
1893 return; 1893 return;
1894 mCalendar->setDefaultCalendar( bd ); 1894 mCalendar->setDefaultCalendar( bd );
1895 1895
1896 1896
1897 int count = birthdayList.count(); 1897 int count = birthdayList.count();
1898 int addCount = 0; 1898 int addCount = 0;
1899 KCal::Attendee* a = 0; 1899 KCal::Attendee* a = 0;
1900 1900
1901 //qDebug("CalView 1 %i", count); 1901 //qDebug("CalView 1 %i", count);
1902 1902
1903 QProgressBar bar(count,0 ); 1903 QProgressBar bar(count,0 );
1904 int w = 300; 1904 int w = 300;
1905 if ( QApplication::desktop()->width() < 320 ) 1905 if ( QApplication::desktop()->width() < 320 )
1906 w = 220; 1906 w = 220;
1907 int h = bar.sizeHint().height() ; 1907 int h = bar.sizeHint().height() ;
1908 int dw = QApplication::desktop()->width(); 1908 int dw = QApplication::desktop()->width();
1909 int dh = QApplication::desktop()->height(); 1909 int dh = QApplication::desktop()->height();
1910 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1910 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1911 bar.show(); 1911 bar.show();
1912 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1912 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1913 qApp->processEvents(); 1913 qApp->processEvents();
1914 1914
1915 QDate birthday; 1915 QDate birthday;
1916 QDate anniversary; 1916 QDate anniversary;
1917 QString realName; 1917 QString realName;
1918 QString email; 1918 QString email;
1919 QString assembledName; 1919 QString assembledName;
1920 QString uid; 1920 QString uid;
1921 bool ok = true; 1921 bool ok = true;
1922 for ( int i = 0; i < count; i++) 1922 for ( int i = 0; i < count; i++)
1923 { 1923 {
1924 if ( ! bar.isVisible() ) 1924 if ( ! bar.isVisible() )
1925 return; 1925 return;
1926 bar.setProgress( i ); 1926 bar.setProgress( i );
1927 qApp->processEvents(); 1927 qApp->processEvents();
1928 1928
1929 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1929 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1930 if (!ok) { 1930 if (!ok) {
1931 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1931 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1932 } 1932 }
1933 1933
1934 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1934 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1935 if (!ok) { 1935 if (!ok) {
1936 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1936 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1937 } 1937 }
1938 realName = realNameList[i]; 1938 realName = realNameList[i];
1939 email = emailList[i]; 1939 email = emailList[i];
1940 assembledName = assembledNameList[i]; 1940 assembledName = assembledNameList[i];
1941 uid = uidList[i]; 1941 uid = uidList[i];
1942 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1942 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1943 1943
1944 if ( birthday.isValid() ){ 1944 if ( birthday.isValid() ){
1945 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1945 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1946 KCal::Attendee::ReqParticipant,uid) ; 1946 KCal::Attendee::ReqParticipant,uid) ;
1947 if ( addAnniversary( birthday, assembledName, a, true ) ) 1947 if ( addAnniversary( birthday, assembledName, a, true ) )
1948 ++addCount; 1948 ++addCount;
1949 } 1949 }
1950 1950
1951 if ( anniversary.isValid() ){ 1951 if ( anniversary.isValid() ){
1952 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1952 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1953 KCal::Attendee::ReqParticipant,uid) ; 1953 KCal::Attendee::ReqParticipant,uid) ;
1954 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1954 if ( addAnniversary( anniversary, assembledName, a, false ) )
1955 ++addCount; 1955 ++addCount;
1956 } 1956 }
1957 } 1957 }
1958 1958
1959 mCalendar->setDefaultCalendar( curCal ); 1959 mCalendar->setDefaultCalendar( curCal );
1960 updateView(); 1960 updateView();
1961 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1961 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1962 1962
1963 } 1963 }
1964 1964
1965} 1965}
1966 1966
1967 1967
1968 1968
1969bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1969bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1970{ 1970{
1971 //qDebug("addAnni "); 1971 //qDebug("addAnni ");
1972 Event * ev = new Event(); 1972 Event * ev = new Event();
1973 ev->setOrganizer(KOPrefs::instance()->email()); 1973 ev->setOrganizer(KOPrefs::instance()->email());
1974 if ( a ) { 1974 if ( a ) {
1975 ev->addAttendee( a ); 1975 ev->addAttendee( a );
1976 } 1976 }
1977 QString kind; 1977 QString kind;
1978 if ( birthday ) { 1978 if ( birthday ) {
1979 kind = i18n( "Birthday" ); 1979 kind = i18n( "Birthday" );
1980 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1980 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1981 } 1981 }
1982 else { 1982 else {
1983 kind = i18n( "Anniversary" ); 1983 kind = i18n( "Anniversary" );
1984 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1984 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1985 } 1985 }
1986 ev->setCategories( kind ); 1986 ev->setCategories( kind );
1987 ev->setDtStart( QDateTime(date) ); 1987 ev->setDtStart( QDateTime(date) );
1988 ev->setDtEnd( QDateTime(date) ); 1988 ev->setDtEnd( QDateTime(date) );
1989 ev->setFloats( true ); 1989 ev->setFloats( true );
1990 Recurrence * rec = ev->recurrence(); 1990 Recurrence * rec = ev->recurrence();
1991 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1991 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1992 rec->addYearlyNum( date.month() ); 1992 rec->addYearlyNum( date.month() );
1993 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1993 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1994 delete ev; 1994 delete ev;
1995 return false; 1995 return false;
1996 } 1996 }
1997 return true; 1997 return true;
1998 1998
1999} 1999}
2000bool CalendarView::importQtopia( const QString &categories, 2000bool CalendarView::importQtopia( const QString &categories,
2001 const QString &datebook, 2001 const QString &datebook,
2002 const QString &todolist ) 2002 const QString &todolist )
2003{ 2003{
2004 2004
2005 QtopiaFormat qtopiaFormat; 2005 QtopiaFormat qtopiaFormat;
2006 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2006 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2007 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 2007 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
2008 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 2008 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
2009 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 2009 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
2010 2010
2011 updateView(); 2011 updateView();
2012 return true; 2012 return true;
2013 2013
2014#if 0 2014#if 0
2015 mGlobalSyncMode = SYNC_MODE_QTOPIA; 2015 mGlobalSyncMode = SYNC_MODE_QTOPIA;
2016 mCurrentSyncDevice = "qtopia-XML"; 2016 mCurrentSyncDevice = "qtopia-XML";
2017 if ( mSyncManager->mAskForPreferences ) 2017 if ( mSyncManager->mAskForPreferences )
2018 edit_sync_options(); 2018 edit_sync_options();
2019 qApp->processEvents(); 2019 qApp->processEvents();
2020 CalendarLocal* calendar = new CalendarLocal(); 2020 CalendarLocal* calendar = new CalendarLocal();
2021 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2021 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2022 bool syncOK = false; 2022 bool syncOK = false;
2023 QtopiaFormat qtopiaFormat; 2023 QtopiaFormat qtopiaFormat;
2024 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2024 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2025 bool loadOk = true; 2025 bool loadOk = true;
2026 if ( !categories.isEmpty() ) 2026 if ( !categories.isEmpty() )
2027 loadOk = qtopiaFormat.load( calendar, categories ); 2027 loadOk = qtopiaFormat.load( calendar, categories );
2028 if ( loadOk && !datebook.isEmpty() ) 2028 if ( loadOk && !datebook.isEmpty() )
2029 loadOk = qtopiaFormat.load( calendar, datebook ); 2029 loadOk = qtopiaFormat.load( calendar, datebook );
2030 if ( loadOk && !todolist.isEmpty() ) 2030 if ( loadOk && !todolist.isEmpty() )
2031 loadOk = qtopiaFormat.load( calendar, todolist ); 2031 loadOk = qtopiaFormat.load( calendar, todolist );
2032 2032
2033 if ( loadOk ) { 2033 if ( loadOk ) {
2034 getEventViewerDialog()->setSyncMode( true ); 2034 getEventViewerDialog()->setSyncMode( true );
2035 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2035 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2036 getEventViewerDialog()->setSyncMode( false ); 2036 getEventViewerDialog()->setSyncMode( false );
2037 qApp->processEvents(); 2037 qApp->processEvents();
2038 if ( syncOK ) { 2038 if ( syncOK ) {
2039 if ( mSyncManager->mWriteBackFile ) 2039 if ( mSyncManager->mWriteBackFile )
2040 { 2040 {
2041 // write back XML file 2041 // write back XML file
2042 2042
2043 } 2043 }
2044 setModified( true ); 2044 setModified( true );
2045 } 2045 }
2046 } else { 2046 } else {
2047 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2047 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2048 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2048 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2049 question, i18n("Ok")) ; 2049 question, i18n("Ok")) ;
2050 } 2050 }
2051 delete calendar; 2051 delete calendar;
2052 updateView(); 2052 updateView();
2053 return syncOK; 2053 return syncOK;
2054 2054
2055 2055
2056#endif 2056#endif
2057 2057
2058} 2058}
2059 2059
2060void CalendarView::setSyncEventsReadOnly() 2060void CalendarView::setSyncEventsReadOnly()
2061{ 2061{
2062 mCalendar->setSyncEventsReadOnly(); 2062 mCalendar->setSyncEventsReadOnly();
2063} 2063}
2064 2064
2065bool CalendarView::loadCalendars() 2065bool CalendarView::loadCalendars()
2066{ 2066{
2067 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2067 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2068 KopiCalendarFile * cal = calendars.first(); 2068 KopiCalendarFile * cal = calendars.first();
2069 mCalendar->setDefaultCalendar( 1 ); 2069 mCalendar->setDefaultCalendar( 1 );
2070 openCalendar( MainWindow::defaultFileName(), false ); 2070 openCalendar( MainWindow::defaultFileName(), false );
2071 cal = calendars.next(); 2071 cal = calendars.next();
2072 while ( cal ) { 2072 while ( cal ) {
2073 addCalendar( cal ); 2073 addCalendar( cal );
2074 cal = calendars.next(); 2074 cal = calendars.next();
2075 } 2075 }
2076 restoreCalendarSettings(); 2076 restoreCalendarSettings();
2077 return true; 2077 return true;
2078} 2078}
2079bool CalendarView::restoreCalendarSettings() 2079bool CalendarView::restoreCalendarSettings()
2080{ 2080{
2081 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2081 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2082 KopiCalendarFile * cal = calendars.first(); 2082 KopiCalendarFile * cal = calendars.first();
2083 while ( cal ) { 2083 while ( cal ) {
2084 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2084 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2085 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2085 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2086 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2086 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2087 if ( cal->isStandard ) 2087 if ( cal->isStandard )
2088 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2088 mCalendar->setDefaultCalendar( cal->mCalNumber );
2089 cal = calendars.next(); 2089 cal = calendars.next();
2090 } 2090 }
2091 setSyncEventsReadOnly(); 2091 setSyncEventsReadOnly();
2092 mCalendar->reInitAlarmSettings(); 2092 mCalendar->reInitAlarmSettings();
2093 updateUnmanagedViews(); 2093 updateUnmanagedViews();
2094 updateView(); 2094 updateView();
2095 return true; 2095 return true;
2096} 2096}
2097void CalendarView::addCalendarId( int id ) 2097void CalendarView::addCalendarId( int id )
2098{ 2098{
2099 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2099 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2100 if ( cal ) 2100 if ( cal )
2101 addCalendar( cal ); 2101 addCalendar( cal );
2102} 2102}
2103bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2103bool CalendarView::addCalendar( KopiCalendarFile * cal )
2104{ 2104{
2105 cal->mErrorOnLoad = false; 2105 cal->mErrorOnLoad = false;
2106 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2106 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2107 cal->mLoadDt = QDateTime::currentDateTime(); 2107 cal->mLoadDt = QDateTime::currentDateTime();
2108 return true; 2108 return true;
2109 } 2109 }
2110 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2110 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2111 cal->mErrorOnLoad = true; 2111 cal->mErrorOnLoad = true;
2112 return false; 2112 return false;
2113} 2113}
2114bool CalendarView::openCalendar(QString filename, bool merge) 2114bool CalendarView::openCalendar(QString filename, bool merge)
2115{ 2115{
2116 2116
2117 if (filename.isEmpty()) { 2117 if (filename.isEmpty()) {
2118 return false; 2118 return false;
2119 } 2119 }
2120 2120
2121 if (!QFile::exists(filename)) { 2121 if (!QFile::exists(filename)) {
2122 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2122 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2123 return false; 2123 return false;
2124 } 2124 }
2125 2125
2126 globalFlagBlockAgenda = 1; 2126 globalFlagBlockAgenda = 1;
2127 clearAllViews(); 2127 clearAllViews();
2128 if (!merge) { 2128 if (!merge) {
2129 mViewManager->setDocumentId( filename ); 2129 mViewManager->setDocumentId( filename );
2130 mCalendar->close(); 2130 mCalendar->close();
2131 } 2131 }
2132 mStorage->setFileName( filename ); 2132 mStorage->setFileName( filename );
2133 2133
2134 if ( mStorage->load() ) { 2134 if ( mStorage->load() ) {
2135 if ( merge ) ;//setModified( true ); 2135 if ( merge ) ;//setModified( true );
2136 else { 2136 else {
2137 //setModified( true ); 2137 //setModified( true );
2138 mViewManager->setDocumentId( filename ); 2138 mViewManager->setDocumentId( filename );
2139 mDialogManager->setDocumentId( filename ); 2139 mDialogManager->setDocumentId( filename );
2140 mTodoList->setDocumentId( filename ); 2140 mTodoList->setDocumentId( filename );
2141 } 2141 }
2142 globalFlagBlockAgenda = 2; 2142 globalFlagBlockAgenda = 2;
2143 // if ( getLastSyncEvent() ) 2143 // if ( getLastSyncEvent() )
2144 // getLastSyncEvent()->setReadOnly( true ); 2144 // getLastSyncEvent()->setReadOnly( true );
2145 mCalendar->reInitAlarmSettings(); 2145 mCalendar->reInitAlarmSettings();
2146 setSyncEventsReadOnly(); 2146 setSyncEventsReadOnly();
2147 updateUnmanagedViews(); 2147 updateUnmanagedViews();
2148 updateView(); 2148 updateView();
2149 if ( filename != MainWindow::defaultFileName() ) { 2149 if ( filename != MainWindow::defaultFileName() ) {
2150 saveCalendar( MainWindow::defaultFileName() ); 2150 saveCalendar( MainWindow::defaultFileName() );
2151 } else { 2151 } else {
2152 QFileInfo finf ( MainWindow::defaultFileName()); 2152 QFileInfo finf ( MainWindow::defaultFileName());
2153 if ( finf.exists() ) { 2153 if ( finf.exists() ) {
2154 setLoadedFileVersion( finf.lastModified () ); 2154 setLoadedFileVersion( finf.lastModified () );
2155 } 2155 }
2156 } 2156 }
2157 return true; 2157 return true;
2158 } else { 2158 } else {
2159 // while failing to load, the calendar object could 2159 // while failing to load, the calendar object could
2160 // have become partially populated. Clear it out. 2160 // have become partially populated. Clear it out.
2161 if ( !merge ) { 2161 if ( !merge ) {
2162 mCalendar->close(); 2162 mCalendar->close();
2163 mViewManager->setDocumentId( filename ); 2163 mViewManager->setDocumentId( filename );
2164 mDialogManager->setDocumentId( filename ); 2164 mDialogManager->setDocumentId( filename );
2165 mTodoList->setDocumentId( filename ); 2165 mTodoList->setDocumentId( filename );
2166 } 2166 }
2167 2167
2168 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2168 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2169 2169
2170 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2170 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2171 globalFlagBlockAgenda = 2; 2171 globalFlagBlockAgenda = 2;
2172 mCalendar->reInitAlarmSettings(); 2172 mCalendar->reInitAlarmSettings();
2173 setSyncEventsReadOnly(); 2173 setSyncEventsReadOnly();
2174 updateUnmanagedViews(); 2174 updateUnmanagedViews();
2175 updateView(); 2175 updateView();
2176 } 2176 }
2177 return false; 2177 return false;
2178} 2178}
2179void CalendarView::mergeFile( QString fn ) 2179void CalendarView::mergeFile( QString fn )
2180{ 2180{
2181 clearAllViews(); 2181 clearAllViews();
2182 mCalendar->mergeCalendarFile( fn ); 2182 mCalendar->mergeCalendarFile( fn );
2183 mCalendar->reInitAlarmSettings(); 2183 mCalendar->reInitAlarmSettings();
2184 setSyncEventsReadOnly(); 2184 setSyncEventsReadOnly();
2185 updateUnmanagedViews(); 2185 updateUnmanagedViews();
2186 updateView(); 2186 updateView();
2187} 2187}
2188void CalendarView::showOpenError() 2188void CalendarView::showOpenError()
2189{ 2189{
2190 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2190 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2191} 2191}
2192void CalendarView::setLoadedFileVersion(QDateTime dt) 2192void CalendarView::setLoadedFileVersion(QDateTime dt)
2193{ 2193{
2194 loadedFileVersion = dt; 2194 loadedFileVersion = dt;
2195} 2195}
2196bool CalendarView::checkFileChanged(QString fn) 2196bool CalendarView::checkFileChanged(QString fn)
2197{ 2197{
2198 QFileInfo finf ( fn ); 2198 QFileInfo finf ( fn );
2199 if ( !finf.exists() ) 2199 if ( !finf.exists() )
2200 return true; 2200 return true;
2201 QDateTime dt = finf.lastModified (); 2201 QDateTime dt = finf.lastModified ();
2202 if ( dt <= loadedFileVersion ) 2202 if ( dt <= loadedFileVersion )
2203 return false; 2203 return false;
2204 return true; 2204 return true;
2205 2205
2206} 2206}
2207void CalendarView::watchSavedFile() 2207void CalendarView::watchSavedFile()
2208{ 2208{
2209 QFileInfo finf ( MainWindow::defaultFileName()); 2209 QFileInfo finf ( MainWindow::defaultFileName());
2210 if ( !finf.exists() ) 2210 if ( !finf.exists() )
2211 return; 2211 return;
2212 QDateTime dt = finf.lastModified (); 2212 QDateTime dt = finf.lastModified ();
2213 if ( dt < loadedFileVersion ) { 2213 if ( dt < loadedFileVersion ) {
2214 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2214 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2215 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2215 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2216 return; 2216 return;
2217 } 2217 }
2218 loadedFileVersion = dt; 2218 loadedFileVersion = dt;
2219} 2219}
2220bool CalendarView::checkAllFileVersions() 2220bool CalendarView::checkAllFileVersions()
2221{ 2221{
2222 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2222 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2223 KopiCalendarFile * cal = calendars.first(); 2223 KopiCalendarFile * cal = calendars.first();
2224 mCalendar->setDefaultCalendar( 1 ); 2224 mCalendar->setDefaultCalendar( 1 );
2225 mCalendar->setDefaultCalendarEnabledOnly(); 2225 mCalendar->setDefaultCalendarEnabledOnly();
2226 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2226 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2227 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2227 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2228 restoreCalendarSettings(); 2228 restoreCalendarSettings();
2229 return false; 2229 return false;
2230 } 2230 }
2231 } 2231 }
2232 cal = calendars.next(); 2232 cal = calendars.next();
2233 QDateTime storeTemp = loadedFileVersion; 2233 QDateTime storeTemp = loadedFileVersion;
2234 while ( cal ) { 2234 while ( cal ) {
2235 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2235 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2236 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2236 mCalendar->setDefaultCalendar( cal->mCalNumber );
2237 mCalendar->setDefaultCalendarEnabledOnly(); 2237 mCalendar->setDefaultCalendarEnabledOnly();
2238 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2238 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2239 if ( !checkFileVersion(cal->mFileName )) { 2239 if ( !checkFileVersion(cal->mFileName )) {
2240 loadedFileVersion = storeTemp; 2240 loadedFileVersion = storeTemp;
2241 restoreCalendarSettings(); 2241 restoreCalendarSettings();
2242 return false; 2242 return false;
2243 } 2243 }
2244 } 2244 }
2245 cal = calendars.next(); 2245 cal = calendars.next();
2246 } 2246 }
2247 loadedFileVersion = storeTemp; 2247 loadedFileVersion = storeTemp;
2248 return true; 2248 return true;
2249} 2249}
2250bool CalendarView::checkFileVersion(QString fn) 2250bool CalendarView::checkFileVersion(QString fn)
2251{ 2251{
2252 QFileInfo finf ( fn ); 2252 QFileInfo finf ( fn );
2253 if ( !finf.exists() ) 2253 if ( !finf.exists() )
2254 return true; 2254 return true;
2255 QDateTime dt = finf.lastModified (); 2255 QDateTime dt = finf.lastModified ();
2256 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2256 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2257 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2257 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2258 if ( dt <= loadedFileVersion ) 2258 if ( dt <= loadedFileVersion )
2259 return true; 2259 return true;
2260 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 2260 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
2261 i18n("KO/Pi Warning"),i18n("Overwrite"), 2261 i18n("KO/Pi Warning"),i18n("Overwrite"),
2262 i18n("Sync+save")); 2262 i18n("Sync+save"));
2263 2263
2264 if ( km == KMessageBox::Cancel ) 2264 if ( km == KMessageBox::Cancel )
2265 return false; 2265 return false;
2266 if ( km == KMessageBox::Yes ) 2266 if ( km == KMessageBox::Yes )
2267 return true; 2267 return true;
2268 2268
2269 setSyncDevice("deleteaftersync" ); 2269 setSyncDevice("deleteaftersync" );
2270 mSyncManager->mAskForPreferences = true; 2270 mSyncManager->mAskForPreferences = true;
2271 mSyncManager->mSyncAlgoPrefs = 3; 2271 mSyncManager->mSyncAlgoPrefs = 3;
2272 mSyncManager->mWriteBackFile = false; 2272 mSyncManager->mWriteBackFile = false;
2273 mSyncManager->mWriteBackExistingOnly = false; 2273 mSyncManager->mWriteBackExistingOnly = false;
2274 mSyncManager->mShowSyncSummary = false; 2274 mSyncManager->mShowSyncSummary = false;
2275 syncCalendar( fn, 3 ); 2275 syncCalendar( fn, 3 );
2276 Event * e = getLastSyncEvent(); 2276 Event * e = getLastSyncEvent();
2277 if ( e ) 2277 if ( e )
2278 mCalendar->deleteEvent( e ); 2278 mCalendar->deleteEvent( e );
2279 return true; 2279 return true;
2280} 2280}
2281bool CalendarView::saveCalendars() 2281bool CalendarView::saveCalendars()
2282{ 2282{
2283 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2283 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2284 KopiCalendarFile * cal = calendars.first(); 2284 KopiCalendarFile * cal = calendars.first();
2285 mCalendar->setDefaultCalendar( 1 ); 2285 mCalendar->setDefaultCalendar( 1 );
2286 mCalendar->setDefaultCalendarEnabledOnly(); 2286 mCalendar->setDefaultCalendarEnabledOnly();
2287 saveCalendar( MainWindow::defaultFileName() ); 2287 saveCalendar( MainWindow::defaultFileName() );
2288 cal = calendars.next(); 2288 cal = calendars.next();
2289 while ( cal ) { 2289 while ( cal ) {
2290 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2290 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2291 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2291 mCalendar->setDefaultCalendar( cal->mCalNumber );
2292 mCalendar->setDefaultCalendarEnabledOnly(); 2292 mCalendar->setDefaultCalendarEnabledOnly();
2293 if ( saveCalendar( cal->mFileName ) ) 2293 if ( saveCalendar( cal->mFileName ) )
2294 cal->mLoadDt = QDateTime::currentDateTime(); 2294 cal->mLoadDt = QDateTime::currentDateTime();
2295 } 2295 }
2296 cal = calendars.next(); 2296 cal = calendars.next();
2297 } 2297 }
2298 restoreCalendarSettings(); 2298 restoreCalendarSettings();
2299 return true; 2299 return true;
2300} 2300}
2301bool CalendarView::saveCalendar( QString filename ) 2301bool CalendarView::saveCalendar( QString filename )
2302{ 2302{
2303 2303
2304 // Store back all unsaved data into calendar object 2304 // Store back all unsaved data into calendar object
2305 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2305 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2306 if ( mViewManager->currentView() ) 2306 if ( mViewManager->currentView() )
2307 mViewManager->currentView()->flushView(); 2307 mViewManager->currentView()->flushView();
2308 2308
2309 2309
2310 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2310 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2311 mStorage->setSaveFormat( new ICalFormat() ); 2311 mStorage->setSaveFormat( new ICalFormat() );
2312 mStorage->setFileName( filename ); 2312 mStorage->setFileName( filename );
2313 bool success; 2313 bool success;
2314 success = mStorage->save(); 2314 success = mStorage->save();
2315 if ( !success ) { 2315 if ( !success ) {
2316 return false; 2316 return false;
2317 } 2317 }
2318 if ( filename == MainWindow::defaultFileName() ) { 2318 if ( filename == MainWindow::defaultFileName() ) {
2319 setLoadedFileVersion( lfv ); 2319 setLoadedFileVersion( lfv );
2320 watchSavedFile(); 2320 watchSavedFile();
2321 } 2321 }
2322 return true; 2322 return true;
2323} 2323}
2324 2324
2325void CalendarView::closeCalendar() 2325void CalendarView::closeCalendar()
2326{ 2326{
2327 2327
2328 // child windows no longer valid 2328 // child windows no longer valid
2329 clearAllViews(); 2329 clearAllViews();
2330 emit closingDown(); 2330 emit closingDown();
2331 2331
2332 mCalendar->close(); 2332 mCalendar->close();
2333 setModified(false); 2333 setModified(false);
2334 updateView(); 2334 updateView();
2335} 2335}
2336 2336
2337void CalendarView::archiveCalendar() 2337void CalendarView::archiveCalendar()
2338{ 2338{
2339 mDialogManager->showArchiveDialog(); 2339 mDialogManager->showArchiveDialog();
2340} 2340}
2341 2341
2342 2342
2343void CalendarView::readSettings() 2343void CalendarView::readSettings()
2344{ 2344{
2345 2345
2346 2346
2347 // mViewManager->showAgendaView(); 2347 // mViewManager->showAgendaView();
2348 QString str; 2348 QString str;
2349 //qDebug("CalendarView::readSettings() "); 2349 //qDebug("CalendarView::readSettings() ");
2350 // read settings from the KConfig, supplying reasonable 2350 // read settings from the KConfig, supplying reasonable
2351 // defaults where none are to be found 2351 // defaults where none are to be found
2352 KConfig *config = KOGlobals::config(); 2352 KConfig *config = KOGlobals::config();
2353#ifndef KORG_NOSPLITTER 2353#ifndef KORG_NOSPLITTER
2354 config->setGroup("KOrganizer Geometry"); 2354 config->setGroup("KOrganizer Geometry");
2355 2355
2356 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2356 QValueList<int> sizes = config->readIntListEntry("Separator1");
2357 if (sizes.count() != 2) { 2357 if (sizes.count() != 2) {
2358 sizes << mDateNavigator->minimumSizeHint().width(); 2358 sizes << mDateNavigator->minimumSizeHint().width();
2359 sizes << 300; 2359 sizes << 300;
2360 } 2360 }
2361 mPanner->setSizes(sizes); 2361 mPanner->setSizes(sizes);
2362 2362
2363 sizes = config->readIntListEntry("Separator2"); 2363 sizes = config->readIntListEntry("Separator2");
2364 if ( ( mResourceView && sizes.count() == 4 ) || 2364 if ( ( mResourceView && sizes.count() == 4 ) ||
2365 ( !mResourceView && sizes.count() == 3 ) ) { 2365 ( !mResourceView && sizes.count() == 3 ) ) {
2366 mLeftSplitter->setSizes(sizes); 2366 mLeftSplitter->setSizes(sizes);
2367 } 2367 }
2368#endif 2368#endif
2369 globalFlagBlockAgenda = 1; 2369 globalFlagBlockAgenda = 1;
2370 mViewManager->showAgendaView(); 2370 mViewManager->showAgendaView();
2371 //mViewManager->readSettings( config ); 2371 //mViewManager->readSettings( config );
2372 mTodoList->restoreLayout(config,QString("Todo Layout")); 2372 mTodoList->restoreLayout(config,QString("Todo Layout"));
2373 readFilterSettings(config); 2373 readFilterSettings(config);
2374 2374
2375#ifdef DESKTOP_VERSION 2375#ifdef DESKTOP_VERSION
2376 config->setGroup("WidgetLayout"); 2376 config->setGroup("WidgetLayout");
2377 QStringList list; 2377 QStringList list;
2378 list = config->readListEntry("MainLayout"); 2378 list = config->readListEntry("MainLayout");
2379 int x,y,w,h; 2379 int x,y,w,h;
2380 if ( ! list.isEmpty() ) { 2380 if ( ! list.isEmpty() ) {
2381 x = list[0].toInt(); 2381 x = list[0].toInt();
2382 y = list[1].toInt(); 2382 y = list[1].toInt();
2383 w = list[2].toInt(); 2383 w = list[2].toInt();
2384 h = list[3].toInt(); 2384 h = list[3].toInt();
2385 KApplication::testCoords( &x,&y,&w,&h ); 2385 KApplication::testCoords( &x,&y,&w,&h );
2386 topLevelWidget()->setGeometry(x,y,w,h); 2386 topLevelWidget()->setGeometry(x,y,w,h);
2387 2387
2388 } else { 2388 } else {
2389 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2389 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2390 } 2390 }
2391 list = config->readListEntry("EditEventLayout"); 2391 list = config->readListEntry("EditEventLayout");
2392 if ( ! list.isEmpty() ) { 2392 if ( ! list.isEmpty() ) {
2393 x = list[0].toInt(); 2393 x = list[0].toInt();
2394 y = list[1].toInt(); 2394 y = list[1].toInt();
2395 w = list[2].toInt(); 2395 w = list[2].toInt();
2396 h = list[3].toInt(); 2396 h = list[3].toInt();
2397 KApplication::testCoords( &x,&y,&w,&h ); 2397 KApplication::testCoords( &x,&y,&w,&h );
2398 mEventEditor->setGeometry(x,y,w,h); 2398 mEventEditor->setGeometry(x,y,w,h);
2399 2399
2400 } 2400 }
2401 list = config->readListEntry("EditTodoLayout"); 2401 list = config->readListEntry("EditTodoLayout");
2402 if ( ! list.isEmpty() ) { 2402 if ( ! list.isEmpty() ) {
2403 x = list[0].toInt(); 2403 x = list[0].toInt();
2404 y = list[1].toInt(); 2404 y = list[1].toInt();
2405 w = list[2].toInt(); 2405 w = list[2].toInt();
2406 h = list[3].toInt(); 2406 h = list[3].toInt();
2407 KApplication::testCoords( &x,&y,&w,&h ); 2407 KApplication::testCoords( &x,&y,&w,&h );
2408 mTodoEditor->setGeometry(x,y,w,h); 2408 mTodoEditor->setGeometry(x,y,w,h);
2409 2409
2410 } 2410 }
2411 list = config->readListEntry("ViewerLayout"); 2411 list = config->readListEntry("ViewerLayout");
2412 if ( ! list.isEmpty() ) { 2412 if ( ! list.isEmpty() ) {
2413 x = list[0].toInt(); 2413 x = list[0].toInt();
2414 y = list[1].toInt(); 2414 y = list[1].toInt();
2415 w = list[2].toInt(); 2415 w = list[2].toInt();
2416 h = list[3].toInt(); 2416 h = list[3].toInt();
2417 KApplication::testCoords( &x,&y,&w,&h ); 2417 KApplication::testCoords( &x,&y,&w,&h );
2418 getEventViewerDialog()->setGeometry(x,y,w,h); 2418 getEventViewerDialog()->setGeometry(x,y,w,h);
2419 } 2419 }
2420#endif 2420#endif
2421 config->setGroup( "Views" ); 2421 config->setGroup( "Views" );
2422 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2422 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2423 2423
2424 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2424 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2425 2425
2426 int resetval = 0; 2426 int resetval = 0;
2427 int maxVal = 0; 2427 int maxVal = 0;
2428 if (sizes.count() != 3) { 2428 if (sizes.count() != 3) {
2429 if ( KOPrefs::instance()->mVerticalScreen ) { 2429 if ( KOPrefs::instance()->mVerticalScreen ) {
2430 resetval = mDateNavigator->sizeHint().width()+2; 2430 resetval = mDateNavigator->sizeHint().width()+2;
2431 } else { 2431 } else {
2432 resetval = mDateNavigator->sizeHint().height()+2; 2432 resetval = mDateNavigator->sizeHint().height()+2;
2433 } 2433 }
2434 } 2434 }
2435 if ( resetval ) { 2435 if ( resetval ) {
2436 sizes.clear(); 2436 sizes.clear();
2437 if ( KOPrefs::instance()->mVerticalScreen ) { 2437 if ( KOPrefs::instance()->mVerticalScreen ) {
2438 maxVal = QApplication::desktop()->width() -10; 2438 maxVal = QApplication::desktop()->width() -10;
2439 } else { 2439 } else {
2440 maxVal = QApplication::desktop()->height()-10; 2440 maxVal = QApplication::desktop()->height()-10;
2441 } 2441 }
2442 sizes << resetval; 2442 sizes << resetval;
2443 if ( maxVal < resetval + resetval) 2443 if ( maxVal < resetval + resetval)
2444 resetval = maxVal - resetval; 2444 resetval = maxVal - resetval;
2445 sizes << resetval; 2445 sizes << resetval;
2446 sizes << 100; 2446 sizes << 100;
2447 } 2447 }
2448 mLeftFrame->setSizes(sizes); 2448 mLeftFrame->setSizes(sizes);
2449 sizes = config->readIntListEntry("Main Splitter Frame"); 2449 sizes = config->readIntListEntry("Main Splitter Frame");
2450 resetval = 0; 2450 resetval = 0;
2451 maxVal = 0; 2451 maxVal = 0;
2452 if (sizes.count() != 2) { 2452 if (sizes.count() != 2) {
2453 if ( !KOPrefs::instance()->mVerticalScreen ) { 2453 if ( !KOPrefs::instance()->mVerticalScreen ) {
2454 resetval = mDateNavigator->sizeHint().width()+2; 2454 resetval = mDateNavigator->sizeHint().width()+2;
2455 } else { 2455 } else {
2456 resetval = mDateNavigator->sizeHint().height()+2; 2456 resetval = mDateNavigator->sizeHint().height()+2;
2457 } 2457 }
2458 } 2458 }
2459 if ( resetval ) { 2459 if ( resetval ) {
2460 sizes.clear(); 2460 sizes.clear();
2461 if ( !KOPrefs::instance()->mVerticalScreen ) { 2461 if ( !KOPrefs::instance()->mVerticalScreen ) {
2462 maxVal = QApplication::desktop()->width() -10; 2462 maxVal = QApplication::desktop()->width() -10;
2463 } else { 2463 } else {
2464 maxVal = QApplication::desktop()->height()-10; 2464 maxVal = QApplication::desktop()->height()-10;
2465 } 2465 }
2466 sizes << resetval; 2466 sizes << resetval;
2467 if ( maxVal < resetval + resetval) 2467 if ( maxVal < resetval + resetval)
2468 resetval = maxVal - resetval; 2468 resetval = maxVal - resetval;
2469 sizes << resetval; 2469 sizes << resetval;
2470 } 2470 }
2471 mMainFrame->setSizes(sizes); 2471 mMainFrame->setSizes(sizes);
2472 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2472 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2473 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2473 else if ( dateCount == 7 ) mNavigator->selectWeek();
2474 else mNavigator->selectDates( dateCount ); 2474 else mNavigator->selectDates( dateCount );
2475 // mViewManager->readSettings( config ); 2475 // mViewManager->readSettings( config );
2476 updateConfig(); 2476 updateConfig();
2477 globalFlagBlockAgenda = 2; 2477 globalFlagBlockAgenda = 2;
2478 mViewManager->readSettings( config ); 2478 mViewManager->readSettings( config );
2479 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2479 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2480} 2480}
2481 2481
2482void CalendarView::checkSuspendAlarm() 2482void CalendarView::checkSuspendAlarm()
2483{ 2483{
2484 if ( mSuspendTimer->isActive() ) { 2484 if ( mSuspendTimer->isActive() ) {
2485 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2485 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2486 } 2486 }
2487} 2487}
2488void CalendarView::writeSettings() 2488void CalendarView::writeSettings()
2489{ 2489{
2490 // kdDebug() << "CalendarView::writeSettings" << endl; 2490 // kdDebug() << "CalendarView::writeSettings" << endl;
2491 2491
2492 KConfig *config = KOGlobals::config(); 2492 KConfig *config = KOGlobals::config();
2493 2493
2494 mViewManager->writeSettings( config ); 2494 mViewManager->writeSettings( config );
2495 mTodoList->saveLayout(config,QString("Todo Layout")); 2495 mTodoList->saveLayout(config,QString("Todo Layout"));
2496 mDialogManager->writeSettings( config ); 2496 mDialogManager->writeSettings( config );
2497 //KOPrefs::instance()->usrWriteConfig(); 2497 //KOPrefs::instance()->usrWriteConfig();
2498 KOPrefs::instance()->writeConfig(); 2498 KOPrefs::instance()->writeConfig();
2499 2499
2500 writeFilterSettings(config); 2500 writeFilterSettings(config);
2501 config->setGroup( "AppRun" ); 2501 config->setGroup( "AppRun" );
2502 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2502 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2503 int days = dt.daysTo( QDate::currentDate() ); 2503 int days = dt.daysTo( QDate::currentDate() );
2504 dt = dt.addDays( days ); 2504 dt = dt.addDays( days );
2505 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2505 int secs = dt.secsTo( QDateTime::currentDateTime() );
2506 config->writeEntry( "LatestProgramStopDays", days ); 2506 config->writeEntry( "LatestProgramStopDays", days );
2507 config->writeEntry( "LatestProgramStopSecs", secs ); 2507 config->writeEntry( "LatestProgramStopSecs", secs );
2508 //qDebug("KO: Writing stop time: %d ", secs); 2508 //qDebug("KO: Writing stop time: %d ", secs);
2509 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2509 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2510 //QDateTime latest = dt.addSecs ( secs ); 2510 //QDateTime latest = dt.addSecs ( secs );
2511 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2511 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2512 config->setGroup( "Views" ); 2512 config->setGroup( "Views" );
2513 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2513 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2514 2514
2515#if 0 2515#if 0
2516 qDebug("********************* "); 2516 qDebug("********************* ");
2517 qDebug("Testcode secsto "); 2517 qDebug("Testcode secsto ");
2518 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2518 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2519 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2519 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2520 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2520 int secsto = dt_nodaylight.secsTo( dt_daylight );
2521 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2521 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2522 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2522 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2523 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2523 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2524 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2524 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2525 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2525 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2526 qDebug("********************* testcode end"); 2526 qDebug("********************* testcode end");
2527 2527
2528#endif 2528#endif
2529 2529
2530 QValueList<int> listINT = mLeftFrame->sizes(); 2530 QValueList<int> listINT = mLeftFrame->sizes();
2531 config->writeEntry("Left Splitter Frame",listINT); 2531 config->writeEntry("Left Splitter Frame",listINT);
2532 QValueList<int> listINT2 = mMainFrame->sizes(); 2532 QValueList<int> listINT2 = mMainFrame->sizes();
2533 config->writeEntry("Main Splitter Frame",listINT2); 2533 config->writeEntry("Main Splitter Frame",listINT2);
2534#ifdef DESKTOP_VERSION 2534#ifdef DESKTOP_VERSION
2535 config->setGroup("WidgetLayout"); 2535 config->setGroup("WidgetLayout");
2536 QStringList list ;//= config->readListEntry("MainLayout"); 2536 QStringList list ;//= config->readListEntry("MainLayout");
2537 int x,y,w,h; 2537 int x,y,w,h;
2538 QWidget* wid; 2538 QWidget* wid;
2539 wid = topLevelWidget(); 2539 wid = topLevelWidget();
2540 x = wid->geometry().x(); 2540 x = wid->geometry().x();
2541 y = wid->geometry().y(); 2541 y = wid->geometry().y();
2542 w = wid->width(); 2542 w = wid->width();
2543 h = wid->height(); 2543 h = wid->height();
2544 list.clear(); 2544 list.clear();
2545 list << QString::number( x ); 2545 list << QString::number( x );
2546 list << QString::number( y ); 2546 list << QString::number( y );
2547 list << QString::number( w ); 2547 list << QString::number( w );
2548 list << QString::number( h ); 2548 list << QString::number( h );
2549 config->writeEntry("MainLayout",list ); 2549 config->writeEntry("MainLayout",list );
2550 2550
2551 wid = mEventEditor; 2551 wid = mEventEditor;
2552 x = wid->geometry().x(); 2552 x = wid->geometry().x();
2553 y = wid->geometry().y(); 2553 y = wid->geometry().y();
2554 w = wid->width(); 2554 w = wid->width();
2555 h = wid->height(); 2555 h = wid->height();
2556 list.clear(); 2556 list.clear();
2557 list << QString::number( x ); 2557 list << QString::number( x );
2558 list << QString::number( y ); 2558 list << QString::number( y );
2559 list << QString::number( w ); 2559 list << QString::number( w );
2560 list << QString::number( h ); 2560 list << QString::number( h );
2561 config->writeEntry("EditEventLayout",list ); 2561 config->writeEntry("EditEventLayout",list );
2562 2562
2563 wid = mTodoEditor; 2563 wid = mTodoEditor;
2564 x = wid->geometry().x(); 2564 x = wid->geometry().x();
2565 y = wid->geometry().y(); 2565 y = wid->geometry().y();
2566 w = wid->width(); 2566 w = wid->width();
2567 h = wid->height(); 2567 h = wid->height();
2568 list.clear(); 2568 list.clear();
2569 list << QString::number( x ); 2569 list << QString::number( x );
2570 list << QString::number( y ); 2570 list << QString::number( y );
2571 list << QString::number( w ); 2571 list << QString::number( w );
2572 list << QString::number( h ); 2572 list << QString::number( h );
2573 config->writeEntry("EditTodoLayout",list ); 2573 config->writeEntry("EditTodoLayout",list );
2574 wid = getEventViewerDialog(); 2574 wid = getEventViewerDialog();
2575 x = wid->geometry().x(); 2575 x = wid->geometry().x();
2576 y = wid->geometry().y(); 2576 y = wid->geometry().y();
2577 w = wid->width(); 2577 w = wid->width();
2578 h = wid->height(); 2578 h = wid->height();
2579 list.clear(); 2579 list.clear();
2580 list << QString::number( x ); 2580 list << QString::number( x );
2581 list << QString::number( y ); 2581 list << QString::number( y );
2582 list << QString::number( w ); 2582 list << QString::number( w );
2583 list << QString::number( h ); 2583 list << QString::number( h );
2584 config->writeEntry("ViewerLayout",list ); 2584 config->writeEntry("ViewerLayout",list );
2585 wid = mDialogManager->getSearchDialog(); 2585 wid = mDialogManager->getSearchDialog();
2586 if ( wid ) { 2586 if ( wid ) {
2587 x = wid->geometry().x(); 2587 x = wid->geometry().x();
2588 y = wid->geometry().y(); 2588 y = wid->geometry().y();
2589 w = wid->width(); 2589 w = wid->width();
2590 h = wid->height(); 2590 h = wid->height();
2591 list.clear(); 2591 list.clear();
2592 list << QString::number( x ); 2592 list << QString::number( x );
2593 list << QString::number( y ); 2593 list << QString::number( y );
2594 list << QString::number( w ); 2594 list << QString::number( w );
2595 list << QString::number( h ); 2595 list << QString::number( h );
2596 config->writeEntry("SearchLayout",list ); 2596 config->writeEntry("SearchLayout",list );
2597 } 2597 }
2598#endif 2598#endif
2599 2599
2600 2600
2601 config->sync(); 2601 config->sync();
2602} 2602}
2603 2603
2604void CalendarView::readFilterSettings(KConfig *config) 2604void CalendarView::readFilterSettings(KConfig *config)
2605{ 2605{
2606 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2606 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2607 2607
2608 mFilters.clear(); 2608 mFilters.clear();
2609 2609
2610 config->setGroup("General"); 2610 config->setGroup("General");
2611 QStringList filterList = config->readListEntry("CalendarFilters"); 2611 QStringList filterList = config->readListEntry("CalendarFilters");
2612 2612
2613 QStringList::ConstIterator it = filterList.begin(); 2613 QStringList::ConstIterator it = filterList.begin();
2614 QStringList::ConstIterator end = filterList.end(); 2614 QStringList::ConstIterator end = filterList.end();
2615 while(it != end) { 2615 while(it != end) {
2616 // kdDebug() << " filter: " << (*it) << endl; 2616 // kdDebug() << " filter: " << (*it) << endl;
2617 2617
2618 CalFilter *filter; 2618 CalFilter *filter;
2619 filter = new CalFilter(*it); 2619 filter = new CalFilter(*it);
2620 config->setGroup("Filter_" + (*it).utf8()); 2620 config->setGroup("Filter_" + (*it).utf8());
2621 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2621 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2622 filter->setCriteria(config->readNumEntry("Criteria",0)); 2622 filter->setCriteria(config->readNumEntry("Criteria",0));
2623 filter->setCategoryList(config->readListEntry("CategoryList")); 2623 filter->setCategoryList(config->readListEntry("CategoryList"));
2624 mFilters.append(filter); 2624 mFilters.append(filter);
2625 2625
2626 ++it; 2626 ++it;
2627 } 2627 }
2628 2628
2629 if (mFilters.count() == 0) { 2629 if (mFilters.count() == 0) {
2630 CalFilter *filter = new CalFilter(i18n("Default")); 2630 CalFilter *filter = new CalFilter(i18n("Default"));
2631 mFilters.append(filter); 2631 mFilters.append(filter);
2632 } 2632 }
2633 mFilterView->updateFilters(); 2633 mFilterView->updateFilters();
2634 config->setGroup("FilterView"); 2634 config->setGroup("FilterView");
2635 2635
2636 mFilterView->blockSignals(true); 2636 mFilterView->blockSignals(true);
2637 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2637 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2638 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2638 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2639 mFilterView->blockSignals(false); 2639 mFilterView->blockSignals(false);
2640 // We do it manually to avoid it being done twice by the above calls 2640 // We do it manually to avoid it being done twice by the above calls
2641 updateFilter(); 2641 updateFilter();
2642} 2642}
2643 2643
2644void CalendarView::writeFilterSettings(KConfig *config) 2644void CalendarView::writeFilterSettings(KConfig *config)
2645{ 2645{
2646 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2646 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2647 2647
2648 QStringList filterList; 2648 QStringList filterList;
2649 2649
2650 CalFilter *filter = mFilters.first(); 2650 CalFilter *filter = mFilters.first();
2651 while(filter) { 2651 while(filter) {
2652 // kdDebug() << " fn: " << filter->name() << endl; 2652 // kdDebug() << " fn: " << filter->name() << endl;
2653 filterList << filter->name(); 2653 filterList << filter->name();
2654 config->setGroup("Filter_" + filter->name().utf8()); 2654 config->setGroup("Filter_" + filter->name().utf8());
2655 config->writeEntry("Criteria",filter->criteria()); 2655 config->writeEntry("Criteria",filter->criteria());
2656 config->writeEntry("CategoryList",filter->categoryList()); 2656 config->writeEntry("CategoryList",filter->categoryList());
2657 filter = mFilters.next(); 2657 filter = mFilters.next();
2658 } 2658 }
2659 config->setGroup("General"); 2659 config->setGroup("General");
2660 config->writeEntry("CalendarFilters",filterList); 2660 config->writeEntry("CalendarFilters",filterList);
2661 2661
2662 config->setGroup("FilterView"); 2662 config->setGroup("FilterView");
2663 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2663 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2664 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2664 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2665} 2665}
2666 2666
2667 2667
2668void CalendarView::goToday() 2668void CalendarView::goToday()
2669{ 2669{
2670 if ( mViewManager->currentView()->isMonthView() ) 2670 if ( mViewManager->currentView()->isMonthView() )
2671 mNavigator->selectTodayMonth(); 2671 mNavigator->selectTodayMonth();
2672 else 2672 else
2673 mNavigator->selectToday(); 2673 mNavigator->selectToday();
2674} 2674}
2675 2675
2676void CalendarView::goNext() 2676void CalendarView::goNext()
2677{ 2677{
2678 mNavigator->selectNext(); 2678 mNavigator->selectNext();
2679} 2679}
2680 2680
2681void CalendarView::goPrevious() 2681void CalendarView::goPrevious()
2682{ 2682{
2683 mNavigator->selectPrevious(); 2683 mNavigator->selectPrevious();
2684} 2684}
2685void CalendarView::goNextMonth() 2685void CalendarView::goNextMonth()
2686{ 2686{
2687 mNavigator->selectNextMonth(); 2687 mNavigator->selectNextMonth();
2688} 2688}
2689 2689
2690void CalendarView::goPreviousMonth() 2690void CalendarView::goPreviousMonth()
2691{ 2691{
2692 mNavigator->selectPreviousMonth(); 2692 mNavigator->selectPreviousMonth();
2693} 2693}
2694 2694
2695void CalendarView::updateConfig() 2695void CalendarView::updateConfig()
2696{ 2696{
2697 if ( KOPrefs::instance()->mUseAppColors ) 2697 if ( KOPrefs::instance()->mUseAppColors )
2698 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2698 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2699 emit configChanged(); 2699 emit configChanged();
2700 mTodoList->updateConfig(); 2700 mTodoList->updateConfig();
2701 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2701 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2702 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2702 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2703 // To make the "fill window" configurations work 2703 // To make the "fill window" configurations work
2704 //mViewManager->raiseCurrentView(); 2704 //mViewManager->raiseCurrentView();
2705} 2705}
2706 2706
2707 2707
2708void CalendarView::eventChanged(Event *event) 2708void CalendarView::eventChanged(Event *event)
2709{ 2709{
2710 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2710 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2711 //updateUnmanagedViews(); 2711 //updateUnmanagedViews();
2712} 2712}
2713 2713
2714void CalendarView::eventAdded(Event *event) 2714void CalendarView::eventAdded(Event *event)
2715{ 2715{
2716 changeEventDisplay(event,KOGlobals::EVENTADDED); 2716 changeEventDisplay(event,KOGlobals::EVENTADDED);
2717} 2717}
2718 2718
2719void CalendarView::eventToBeDeleted(Event *) 2719void CalendarView::eventToBeDeleted(Event *)
2720{ 2720{
2721 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2721 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2722} 2722}
2723 2723
2724void CalendarView::eventDeleted() 2724void CalendarView::eventDeleted()
2725{ 2725{
2726 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2726 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2727} 2727}
2728void CalendarView::changeTodoDisplay(Todo *which, int action) 2728void CalendarView::changeTodoDisplay(Todo *which, int action)
2729{ 2729{
2730 changeIncidenceDisplay((Incidence *)which, action); 2730 changeIncidenceDisplay((Incidence *)which, action);
2731 mDateNavigator->updateView(); //LR 2731 mDateNavigator->updateView(); //LR
2732 //mDialogManager->updateSearchDialog(); 2732 //mDialogManager->updateSearchDialog();
2733 2733
2734 if (which) { 2734 if (which) {
2735 mViewManager->updateWNview(); 2735 mViewManager->updateWNview();
2736 //mTodoList->updateView(); 2736 //mTodoList->updateView();
2737 } 2737 }
2738 2738
2739} 2739}
2740 2740
2741void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2741void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2742{ 2742{
2743 updateUnmanagedViews(); 2743 updateUnmanagedViews();
2744 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2744 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2745 if ( action == KOGlobals::EVENTDELETED ) { //delete 2745 if ( action == KOGlobals::EVENTDELETED ) { //delete
2746 mCalendar->checkAlarmForIncidence( 0, true ); 2746 mCalendar->checkAlarmForIncidence( 0, true );
2747 if ( mEventViewerDialog ) 2747 if ( mEventViewerDialog )
2748 mEventViewerDialog->hide(); 2748 mEventViewerDialog->hide();
2749 } 2749 }
2750 else 2750 else
2751 mCalendar->checkAlarmForIncidence( which , false ); 2751 mCalendar->checkAlarmForIncidence( which , false );
2752} 2752}
2753 2753
2754// most of the changeEventDisplays() right now just call the view's 2754// most of the changeEventDisplays() right now just call the view's
2755// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2755// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2756void CalendarView::changeEventDisplay(Event *which, int action) 2756void CalendarView::changeEventDisplay(Event *which, int action)
2757{ 2757{
2758 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2758 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2759 changeIncidenceDisplay((Incidence *)which, action); 2759 changeIncidenceDisplay((Incidence *)which, action);
2760 static bool clearallviews = false; 2760 static bool clearallviews = false;
2761 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2761 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2762 if ( clearallviews ) { 2762 if ( clearallviews ) {
2763 clearAllViews(); 2763 clearAllViews();
2764 clearallviews = false; 2764 clearallviews = false;
2765 } 2765 }
2766 return; 2766 return;
2767 } 2767 }
2768 clearallviews = true; 2768 clearallviews = true;
2769 mDateNavigator->updateView(); 2769 mDateNavigator->updateView();
2770 //mDialogManager->updateSearchDialog(); 2770 //mDialogManager->updateSearchDialog();
2771 if (which) { 2771 if (which) {
2772 // If there is an event view visible update the display 2772 // If there is an event view visible update the display
2773 mViewManager->currentView()->changeEventDisplay(which,action); 2773 mViewManager->currentView()->changeEventDisplay(which,action);
2774 // TODO: check, if update needed 2774 // TODO: check, if update needed
2775 // if (which->getTodoStatus()) { 2775 // if (which->getTodoStatus()) {
2776 mTodoList->updateView(); 2776 mTodoList->updateView();
2777 if ( action != KOGlobals::EVENTDELETED ) { 2777 if ( action != KOGlobals::EVENTDELETED ) {
2778 mConflictingEvent = which ; 2778 mConflictingEvent = which ;
2779 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) ); 2779 int time = 1000;
2780#ifdef DESKTOP_VERSION
2781 time = 500;
2782#endif
2783 QTimer::singleShot( time, this, SLOT ( checkConflictForEvent() ) );
2780 } 2784 }
2781 // } 2785 // }
2782 } else { 2786 } else {
2783 mViewManager->currentView()->updateView(); 2787 mViewManager->currentView()->updateView();
2784 } 2788 }
2785} 2789}
2786void CalendarView::checkConflictForEvent() 2790void CalendarView::checkConflictForEvent()
2787{ 2791{
2788 2792
2789 if (!KOPrefs::instance()->mConfirm) 2793 if (!KOPrefs::instance()->mConfirm)
2790 return; 2794 return;
2791 if ( ! mConflictingEvent ) return; 2795 if ( ! mConflictingEvent ) return;
2792 QDateTime current = QDateTime::currentDateTime(); 2796 QDateTime current = QDateTime::currentDateTime();
2793 if ( ! mConflictingEvent->matchTime( &current, 0 ) ) { 2797 if ( ! mConflictingEvent->matchTime( &current, 0 ) ) {
2794 mConflictingEvent = 0; 2798 mConflictingEvent = 0;
2795 return; 2799 return;
2796 } 2800 }
2797 QPtrList<Event> testlist = mCalendar->events(); 2801 QPtrList<Event> testlist = mCalendar->events();
2798 Event * test = testlist.first(); 2802 Event * test = testlist.first();
2799 QDateTime conflict; 2803 QDateTime conflict;
2800 QDateTime retVal; 2804 QDateTime retVal;
2801 bool found = false; 2805 bool found = false;
2802 Event * cE = 0; 2806 Event * cE = 0;
2803 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 2807 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
2804 while ( test ) { 2808 while ( test ) {
2805 qApp->processEvents(); 2809 qApp->processEvents();
2806 bool skip = false; 2810 bool skip = false;
2807 if ( found ) 2811 if ( found )
2808 skip = !test->matchTime( &current, &conflict ); 2812 skip = !test->matchTime( &current, &conflict );
2809 else 2813 else
2810 skip = !test->matchTime( &current, 0 ); 2814 skip = !test->matchTime( &current, 0 );
2811 if ( !skip && !test->doesFloat() ) { 2815 if ( !skip && !test->doesFloat() ) {
2812 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) { 2816 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) {
2813 if ( ! found ) { 2817 if ( ! found ) {
2814 conflict = retVal; 2818 conflict = retVal;
2815 cE = test; 2819 cE = test;
2816 } else { 2820 } else {
2817 if ( retVal < conflict ) { 2821 if ( retVal < conflict ) {
2818 conflict = retVal; 2822 conflict = retVal;
2819 cE = test; 2823 cE = test;
2820 } 2824 }
2821 } 2825 }
2822 found = true; 2826 found = true;
2823 } 2827 }
2824 } 2828 }
2825 test = testlist.next(); 2829 test = testlist.next();
2826 } 2830 }
2827 if ( found ) { 2831 if ( found ) {
2828 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ; 2832 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ;
2829 qApp->processEvents(); 2833 qApp->processEvents();
2830 int km = KMessageBox::warningContinueCancel(this,mess, 2834 int km = KMessageBox::warningContinueCancel(this,mess,
2831 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!")); 2835 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!"));
2832 if ( km != KMessageBox::Continue ) 2836 if ( km != KMessageBox::Continue )
2833 return; 2837 return;
2834 2838
2835 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 2839 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
2836 mViewManager->showDayView(); 2840 mViewManager->showDayView();
2837 mNavigator->slotDaySelect( conflict.date() ); 2841 mNavigator->slotDaySelect( conflict.date() );
2838 int hour = conflict.time().hour(); 2842 int hour = conflict.time().hour();
2839 mViewManager->agendaView()->setStartHour( hour ); 2843 mViewManager->agendaView()->setStartHour( hour );
2840 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); 2844 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) );
2841 } else 2845 } else
2842 topLevelWidget()->setCaption( i18n("No conflict found") ); 2846 topLevelWidget()->setCaption( i18n("No conflict found") );
2843 mConflictingEvent = 0; 2847 mConflictingEvent = 0;
2844 return; 2848 return;
2845 2849
2846} 2850}
2847 2851
2848void CalendarView::updateTodoViews() 2852void CalendarView::updateTodoViews()
2849{ 2853{
2850 mTodoList->updateView(); 2854 mTodoList->updateView();
2851 mViewManager->currentView()->updateView(); 2855 mViewManager->currentView()->updateView();
2852 2856
2853} 2857}
2854 2858
2855 2859
2856 2860
2857void CalendarView::clearAllViews() 2861void CalendarView::clearAllViews()
2858{ 2862{
2859 mTodoList->clearList(); 2863 mTodoList->clearList();
2860 mViewManager->clearAllViews(); 2864 mViewManager->clearAllViews();
2861 SearchDialog * sd = mDialogManager->getSearchDialog(); 2865 SearchDialog * sd = mDialogManager->getSearchDialog();
2862 if ( sd ) { 2866 if ( sd ) {
2863 KOListView* kol = sd->listview(); 2867 KOListView* kol = sd->listview();
2864 if ( kol ) 2868 if ( kol )
2865 kol->clearList(); 2869 kol->clearList();
2866 } 2870 }
2867} 2871}
2868void CalendarView::updateView() 2872void CalendarView::updateView()
2869{ 2873{
2870 static bool clearallviews = false; 2874 static bool clearallviews = false;
2871 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2875 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2872 if ( clearallviews ) { 2876 if ( clearallviews ) {
2873 clearAllViews(); 2877 clearAllViews();
2874 clearallviews = false; 2878 clearallviews = false;
2875 } 2879 }
2876 return; 2880 return;
2877 } 2881 }
2878 clearallviews = true; 2882 clearallviews = true;
2879 DateList tmpList = mNavigator->selectedDates(); 2883 DateList tmpList = mNavigator->selectedDates();
2880 2884
2881 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2885 if ( KOPrefs::instance()->mHideNonStartedTodos )
2882 mTodoList->updateView(); 2886 mTodoList->updateView();
2883 // We assume that the navigator only selects consecutive days. 2887 // We assume that the navigator only selects consecutive days.
2884 updateView( tmpList.first(), tmpList.last() ); 2888 updateView( tmpList.first(), tmpList.last() );
2885} 2889}
2886 2890
2887void CalendarView::updateUnmanagedViews() 2891void CalendarView::updateUnmanagedViews()
2888{ 2892{
2889 mDateNavigator->updateDayMatrix(); 2893 mDateNavigator->updateDayMatrix();
2890} 2894}
2891 2895
2892int CalendarView::msgItemDelete(const QString name) 2896int CalendarView::msgItemDelete(const QString name)
2893{ 2897{
2894 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2898 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2895 i18n("This item will be\npermanently deleted."), 2899 i18n("This item will be\npermanently deleted."),
2896 i18n("KO/Pi Confirmation"),i18n("Delete")); 2900 i18n("KO/Pi Confirmation"),i18n("Delete"));
2897} 2901}
2898 2902
2899 2903
2900void CalendarView::edit_cut() 2904void CalendarView::edit_cut()
2901{ 2905{
2902 Event *anEvent=0; 2906 Event *anEvent=0;
2903 2907
2904 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2908 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2905 2909
2906 if (mViewManager->currentView()->isEventView()) { 2910 if (mViewManager->currentView()->isEventView()) {
2907 if ( incidence && incidence->typeID() == eventID ) { 2911 if ( incidence && incidence->typeID() == eventID ) {
2908 anEvent = static_cast<Event *>(incidence); 2912 anEvent = static_cast<Event *>(incidence);
2909 } 2913 }
2910 } 2914 }
2911 2915
2912 if (!anEvent) { 2916 if (!anEvent) {
2913 KNotifyClient::beep(); 2917 KNotifyClient::beep();
2914 return; 2918 return;
2915 } 2919 }
2916 DndFactory factory( mCalendar ); 2920 DndFactory factory( mCalendar );
2917 factory.cutIncidence(anEvent); 2921 factory.cutIncidence(anEvent);
2918 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2922 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2919} 2923}
2920 2924
2921void CalendarView::edit_copy() 2925void CalendarView::edit_copy()
2922{ 2926{
2923 Event *anEvent=0; 2927 Event *anEvent=0;
2924 2928
2925 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2929 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2926 2930
2927 if (mViewManager->currentView()->isEventView()) { 2931 if (mViewManager->currentView()->isEventView()) {
2928 if ( incidence && incidence->typeID() == eventID ) { 2932 if ( incidence && incidence->typeID() == eventID ) {
2929 anEvent = static_cast<Event *>(incidence); 2933 anEvent = static_cast<Event *>(incidence);
2930 } 2934 }
2931 } 2935 }
2932 2936
2933 if (!anEvent) { 2937 if (!anEvent) {
2934 KNotifyClient::beep(); 2938 KNotifyClient::beep();
2935 return; 2939 return;
2936 } 2940 }
2937 DndFactory factory( mCalendar ); 2941 DndFactory factory( mCalendar );
2938 factory.copyIncidence(anEvent); 2942 factory.copyIncidence(anEvent);
2939} 2943}
2940 2944
2941void CalendarView::edit_paste() 2945void CalendarView::edit_paste()
2942{ 2946{
2943 QDate date = mNavigator->selectedDates().first(); 2947 QDate date = mNavigator->selectedDates().first();
2944 2948
2945 DndFactory factory( mCalendar ); 2949 DndFactory factory( mCalendar );
2946 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2950 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2947 2951
2948 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2952 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2949} 2953}
2950void CalendarView::edit_global_options() 2954void CalendarView::edit_global_options()
2951{ 2955{
2952 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2956 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2953 emit save(); 2957 emit save();
2954 emit saveStopTimer(); 2958 emit saveStopTimer();
2955 mDialogManager->showGlobalOptionsDialog(); 2959 mDialogManager->showGlobalOptionsDialog();
2956 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2960 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2957 emit saveStopTimer(); 2961 emit saveStopTimer();
2958 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2962 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2959 i18n("Timezone settings"),i18n("Reload"))) { 2963 i18n("Timezone settings"),i18n("Reload"))) {
2960 qDebug("KO: TZ reload cancelled "); 2964 qDebug("KO: TZ reload cancelled ");
2961 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2965 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2962 return; 2966 return;
2963 } 2967 }
2964 qDebug("KO: Timezone change "); 2968 qDebug("KO: Timezone change ");
2965 loadCalendars(); 2969 loadCalendars();
2966 setModified(true); 2970 setModified(true);
2967 } 2971 }
2968 else 2972 else
2969 qDebug("KO: No tz change "); 2973 qDebug("KO: No tz change ");
2970} 2974}
2971void CalendarView::edit_options() 2975void CalendarView::edit_options()
2972{ 2976{
2973 mDialogManager->showOptionsDialog(); 2977 mDialogManager->showOptionsDialog();
2974} 2978}
2975 2979
2976 2980
2977void CalendarView::slotSelectPickerDate( QDate d) 2981void CalendarView::slotSelectPickerDate( QDate d)
2978{ 2982{
2979 mDateFrame->hide(); 2983 mDateFrame->hide();
2980 if ( mDatePickerMode == 1 ) { 2984 if ( mDatePickerMode == 1 ) {
2981 mNavigator->slotDaySelect( d ); 2985 mNavigator->slotDaySelect( d );
2982 } else if ( mDatePickerMode == 2 ) { 2986 } else if ( mDatePickerMode == 2 ) {
2983 if ( mMoveIncidence->typeID() == todoID ) { 2987 if ( mMoveIncidence->typeID() == todoID ) {
2984 Todo * to = (Todo *) mMoveIncidence; 2988 Todo * to = (Todo *) mMoveIncidence;
2985 QTime tim; 2989 QTime tim;
2986 int len = 0; 2990 int len = 0;
2987 if ( to->hasStartDate() && to->hasDueDate() ) 2991 if ( to->hasStartDate() && to->hasDueDate() )
2988 len = to->dtStart().secsTo( to->dtDue()); 2992 len = to->dtStart().secsTo( to->dtDue());
2989 if ( to->hasDueDate() ) 2993 if ( to->hasDueDate() )
2990 tim = to->dtDue().time(); 2994 tim = to->dtDue().time();
2991 else { 2995 else {
2992 tim = QTime ( 0,0,0 ); 2996 tim = QTime ( 0,0,0 );
2993 to->setFloats( true ); 2997 to->setFloats( true );
2994 to->setHasDueDate( true ); 2998 to->setHasDueDate( true );
2995 } 2999 }
2996 QDateTime dt ( d,tim ); 3000 QDateTime dt ( d,tim );
2997 to->setDtDue( dt ); 3001 to->setDtDue( dt );
2998 3002
2999 if ( to->hasStartDate() ) { 3003 if ( to->hasStartDate() ) {
3000 if ( len>0 ) 3004 if ( len>0 )
3001 to->setDtStart(to->dtDue().addSecs( -len )); 3005 to->setDtStart(to->dtDue().addSecs( -len ));
3002 else 3006 else
3003 if (to->dtStart() > to->dtDue() ) 3007 if (to->dtStart() > to->dtDue() )
3004 to->setDtStart(to->dtDue().addDays( -3 )); 3008 to->setDtStart(to->dtDue().addDays( -3 ));
3005 } 3009 }
3006 3010
3007 todoChanged( to ); 3011 todoChanged( to );
3008 } else if ( mMoveIncidence->typeID() == eventID ) { 3012 } else if ( mMoveIncidence->typeID() == eventID ) {
3009 if ( mMoveIncidence->doesRecur() ) { 3013 if ( mMoveIncidence->doesRecur() ) {
3010#if 0 3014#if 0
3011 // PENDING implement this 3015 // PENDING implement this
3012 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 3016 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
3013 mCalendar()->addIncidence( newInc ); 3017 mCalendar()->addIncidence( newInc );
3014 if ( mMoveIncidence->typeID() == todoID ) 3018 if ( mMoveIncidence->typeID() == todoID )
3015 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 3019 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
3016 else 3020 else
3017 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 3021 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
3018 mMoveIncidence = newInc; 3022 mMoveIncidence = newInc;
3019 3023
3020#endif 3024#endif
3021 } 3025 }
3022 QTime tim = mMoveIncidence->dtStart().time(); 3026 QTime tim = mMoveIncidence->dtStart().time();
3023 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 3027 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
3024 QDateTime dt ( d,tim ); 3028 QDateTime dt ( d,tim );
3025 mMoveIncidence->setDtStart( dt ); 3029 mMoveIncidence->setDtStart( dt );
3026 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 3030 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
3027 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 3031 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
3028 } else if ( mMoveIncidence->typeID() == journalID ) { 3032 } else if ( mMoveIncidence->typeID() == journalID ) {
3029 QTime tim = mMoveIncidence->dtStart().time(); 3033 QTime tim = mMoveIncidence->dtStart().time();
3030 QDateTime dt ( d,tim ); 3034 QDateTime dt ( d,tim );
3031 mMoveIncidence->setDtStart( dt ); 3035 mMoveIncidence->setDtStart( dt );
3032 updateView(); 3036 updateView();
3033 } 3037 }
3034 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 3038 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
3035 } 3039 }
3036} 3040}
3037 3041
3038void CalendarView::removeCategories() 3042void CalendarView::removeCategories()
3039{ 3043{
3040 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3044 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3041 QStringList catList = KOPrefs::instance()->mCustomCategories; 3045 QStringList catList = KOPrefs::instance()->mCustomCategories;
3042 QStringList catIncList; 3046 QStringList catIncList;
3043 QStringList newCatList; 3047 QStringList newCatList;
3044 Incidence* inc = incList.first(); 3048 Incidence* inc = incList.first();
3045 uint i; 3049 uint i;
3046 while ( inc ) { 3050 while ( inc ) {
3047 newCatList.clear(); 3051 newCatList.clear();
3048 catIncList = inc->categories() ; 3052 catIncList = inc->categories() ;
3049 for( i = 0; i< catIncList.count(); ++i ) { 3053 for( i = 0; i< catIncList.count(); ++i ) {
3050 if ( catList.contains (catIncList[i])) 3054 if ( catList.contains (catIncList[i]))
3051 newCatList.append( catIncList[i] ); 3055 newCatList.append( catIncList[i] );
3052 } 3056 }
3053 newCatList.sort(); 3057 newCatList.sort();
3054 inc->setCategories( newCatList.join(",") ); 3058 inc->setCategories( newCatList.join(",") );
3055 inc = incList.next(); 3059 inc = incList.next();
3056 } 3060 }
3057} 3061}
3058 3062
3059int CalendarView::addCategories() 3063int CalendarView::addCategories()
3060{ 3064{
3061 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3065 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3062 QStringList catList = KOPrefs::instance()->mCustomCategories; 3066 QStringList catList = KOPrefs::instance()->mCustomCategories;
3063 QStringList catIncList; 3067 QStringList catIncList;
3064 Incidence* inc = incList.first(); 3068 Incidence* inc = incList.first();
3065 uint i; 3069 uint i;
3066 int count = 0; 3070 int count = 0;
3067 while ( inc ) { 3071 while ( inc ) {
3068 catIncList = inc->categories() ; 3072 catIncList = inc->categories() ;
3069 for( i = 0; i< catIncList.count(); ++i ) { 3073 for( i = 0; i< catIncList.count(); ++i ) {
3070 if ( !catList.contains (catIncList[i])) { 3074 if ( !catList.contains (catIncList[i])) {
3071 catList.append( catIncList[i] ); 3075 catList.append( catIncList[i] );
3072 //qDebug("add cat %s ", catIncList[i].latin1()); 3076 //qDebug("add cat %s ", catIncList[i].latin1());
3073 ++count; 3077 ++count;
3074 } 3078 }
3075 } 3079 }
3076 inc = incList.next(); 3080 inc = incList.next();
3077 } 3081 }
3078 catList.sort(); 3082 catList.sort();
3079 KOPrefs::instance()->mCustomCategories = catList; 3083 KOPrefs::instance()->mCustomCategories = catList;
3080 return count; 3084 return count;
3081} 3085}
3082 3086
3083void CalendarView::editCategories() 3087void CalendarView::editCategories()
3084{ 3088{
3085 qDebug("CalendarView::editCategories() "); 3089 qDebug("CalendarView::editCategories() ");
3086 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this ); 3090 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this );
3087 ced.exec(); 3091 ced.exec();
3088} 3092}
3089void CalendarView::manageCategories() 3093void CalendarView::manageCategories()
3090{ 3094{
3091 KOCatPrefs* cp = new KOCatPrefs(); 3095 KOCatPrefs* cp = new KOCatPrefs();
3092 cp->show(); 3096 cp->show();
3093 int w =cp->sizeHint().width() ; 3097 int w =cp->sizeHint().width() ;
3094 int h = cp->sizeHint().height() ; 3098 int h = cp->sizeHint().height() ;
3095 int dw = QApplication::desktop()->width(); 3099 int dw = QApplication::desktop()->width();
3096 int dh = QApplication::desktop()->height(); 3100 int dh = QApplication::desktop()->height();
3097 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 3101 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
3098 if ( !cp->exec() ) { 3102 if ( !cp->exec() ) {
3099 delete cp; 3103 delete cp;
3100 return; 3104 return;
3101 } 3105 }
3102 int count = 0; 3106 int count = 0;
3103 if ( cp->addCat() ) { 3107 if ( cp->addCat() ) {
3104 count = addCategories(); 3108 count = addCategories();
3105 if ( count ) { 3109 if ( count ) {
3106 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 3110 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
3107 writeSettings(); 3111 writeSettings();
3108 } else 3112 } else
3109 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 3113 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
3110 } else { 3114 } else {
3111 removeCategories(); 3115 removeCategories();
3112 updateView(); 3116 updateView();
3113 } 3117 }
3114 delete cp; 3118 delete cp;
3115} 3119}
3116 3120
3117void CalendarView::beamIncidence(Incidence * Inc) 3121void CalendarView::beamIncidence(Incidence * Inc)
3118{ 3122{
3119 QPtrList<Incidence> delSel ; 3123 QPtrList<Incidence> delSel ;
3120 delSel.append(Inc); 3124 delSel.append(Inc);
3121 beamIncidenceList( delSel ); 3125 beamIncidenceList( delSel );
3122} 3126}
3123void CalendarView::beamCalendar() 3127void CalendarView::beamCalendar()
3124{ 3128{
3125 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 3129 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
3126 //qDebug("beamCalendar() "); 3130 //qDebug("beamCalendar() ");
3127 beamIncidenceList( delSel ); 3131 beamIncidenceList( delSel );
3128} 3132}
3129void CalendarView::beamFilteredCalendar() 3133void CalendarView::beamFilteredCalendar()
3130{ 3134{
3131 QPtrList<Incidence> delSel = mCalendar->incidences(); 3135 QPtrList<Incidence> delSel = mCalendar->incidences();
3132 //qDebug("beamFilteredCalendar() "); 3136 //qDebug("beamFilteredCalendar() ");
3133 beamIncidenceList( delSel ); 3137 beamIncidenceList( delSel );
3134} 3138}
3135void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 3139void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
3136{ 3140{
3137 3141
3138 KOBeamPrefs beamDialog; 3142 KOBeamPrefs beamDialog;
3139 if ( beamDialog.exec () == QDialog::Rejected ) 3143 if ( beamDialog.exec () == QDialog::Rejected )
3140 return; 3144 return;
3141#ifdef DESKTOP_VERSION 3145#ifdef DESKTOP_VERSION
3142 QString fn = locateLocal( "tmp", "kopibeamfile" ); 3146 QString fn = locateLocal( "tmp", "kopibeamfile" );
3143#else 3147#else
3144 QString fn = "/tmp/kopibeamfile"; 3148 QString fn = "/tmp/kopibeamfile";
3145#endif 3149#endif
3146 QString mes; 3150 QString mes;
3147 bool createbup = true; 3151 bool createbup = true;
3148 if ( createbup ) { 3152 if ( createbup ) {
3149 QString description = "\n"; 3153 QString description = "\n";
3150 CalendarLocal* cal = new CalendarLocal(); 3154 CalendarLocal* cal = new CalendarLocal();
3151 if ( beamDialog.beamLocal() ) 3155 if ( beamDialog.beamLocal() )
3152 cal->setLocalTime(); 3156 cal->setLocalTime();
3153 else 3157 else
3154 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3158 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3155 Incidence *incidence = delSel.first(); 3159 Incidence *incidence = delSel.first();
3156 bool addText = false; 3160 bool addText = false;
3157 if ( delSel.count() < 10 ) 3161 if ( delSel.count() < 10 )
3158 addText = true; 3162 addText = true;
3159 else { 3163 else {
3160 description.sprintf(i18n(" %d items?"),delSel.count() ); 3164 description.sprintf(i18n(" %d items?"),delSel.count() );
3161 } 3165 }
3162 while ( incidence ) { 3166 while ( incidence ) {
3163 Incidence *in = incidence->clone(); 3167 Incidence *in = incidence->clone();
3164 if ( ! in->summary().isEmpty() ) { 3168 if ( ! in->summary().isEmpty() ) {
3165 in->setDescription(""); 3169 in->setDescription("");
3166 } else { 3170 } else {
3167 in->setSummary( in->description().left(20)); 3171 in->setSummary( in->description().left(20));
3168 in->setDescription(""); 3172 in->setDescription("");
3169 } 3173 }
3170 if ( addText ) 3174 if ( addText )
3171 description += in->summary() + "\n"; 3175 description += in->summary() + "\n";
3172 cal->addIncidence( in ); 3176 cal->addIncidence( in );
3173 incidence = delSel.next(); 3177 incidence = delSel.next();
3174 } 3178 }
3175 if ( beamDialog.beamVcal() ) { 3179 if ( beamDialog.beamVcal() ) {
3176 fn += ".vcs"; 3180 fn += ".vcs";
3177 FileStorage storage( cal, fn, new VCalFormat ); 3181 FileStorage storage( cal, fn, new VCalFormat );
3178 storage.save(); 3182 storage.save();
3179 } else { 3183 } else {
3180 fn += ".ics"; 3184 fn += ".ics";
3181 FileStorage storage( cal, fn, new ICalFormat( ) ); 3185 FileStorage storage( cal, fn, new ICalFormat( ) );
3182 storage.save(); 3186 storage.save();
3183 } 3187 }
3184 delete cal; 3188 delete cal;
3185 mes = i18n("KO/Pi: Ready for beaming"); 3189 mes = i18n("KO/Pi: Ready for beaming");
3186 topLevelWidget()->setCaption(mes); 3190 topLevelWidget()->setCaption(mes);
3187 KApplication::convert2latin1( fn ); 3191 KApplication::convert2latin1( fn );
3188#ifndef DESKTOP_VERSION 3192#ifndef DESKTOP_VERSION
3189 Ir *ir = new Ir( this ); 3193 Ir *ir = new Ir( this );
3190 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 3194 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
3191 ir->send( fn, description, "text/x-vCalendar" ); 3195 ir->send( fn, description, "text/x-vCalendar" );
3192#endif 3196#endif
3193 } 3197 }
3194} 3198}
3195 3199
3196#ifndef DESKTOP_VERSION 3200#ifndef DESKTOP_VERSION
3197void CalendarView::beamDone( Ir *ir ) 3201void CalendarView::beamDone( Ir *ir )
3198{ 3202{
3199 delete ir; 3203 delete ir;
3200 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 3204 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
3201 topLevelWidget()->raise(); 3205 topLevelWidget()->raise();
3202} 3206}
3203#else 3207#else
3204void CalendarView::beamDone( Ir *){;} 3208void CalendarView::beamDone( Ir *){;}
3205#endif 3209#endif
3206void CalendarView::moveIncidence(Incidence * inc ) 3210void CalendarView::moveIncidence(Incidence * inc )
3207{ 3211{
3208 if ( !inc ) return; 3212 if ( !inc ) return;
3209 showDatePickerPopup(); 3213 showDatePickerPopup();
3210 mDatePickerMode = 2; 3214 mDatePickerMode = 2;
3211 mMoveIncidence = inc ; 3215 mMoveIncidence = inc ;
3212 QDate da; 3216 QDate da;
3213 if ( mMoveIncidence->typeID() == todoID ) { 3217 if ( mMoveIncidence->typeID() == todoID ) {
3214 Todo * to = (Todo *) mMoveIncidence; 3218 Todo * to = (Todo *) mMoveIncidence;
3215 if ( to->hasDueDate() ) 3219 if ( to->hasDueDate() )
3216 da = to->dtDue().date(); 3220 da = to->dtDue().date();
3217 else 3221 else
3218 da = QDate::currentDate(); 3222 da = QDate::currentDate();
3219 } else { 3223 } else {
3220 da = mMoveIncidence->dtStart().date(); 3224 da = mMoveIncidence->dtStart().date();
3221 } 3225 }
3222 //PENDING set date for recurring incidence to date of recurrence 3226 //PENDING set date for recurring incidence to date of recurrence
3223 //mMoveIncidenceOldDate; 3227 //mMoveIncidenceOldDate;
3224 mDatePicker->setDate( da ); 3228 mDatePicker->setDate( da );
3225} 3229}
3226void CalendarView::showDatePickerPopup() 3230void CalendarView::showDatePickerPopup()
3227{ 3231{
3228 if ( mDateFrame->isVisible() ) 3232 if ( mDateFrame->isVisible() )
3229 mDateFrame->hide(); 3233 mDateFrame->hide();
3230 else { 3234 else {
3231 int offX = 0, offY = 0; 3235 int offX = 0, offY = 0;
3232#ifdef DESKTOP_VERSION 3236#ifdef DESKTOP_VERSION
3233 int w =mDatePicker->sizeHint().width() ; 3237 int w =mDatePicker->sizeHint().width() ;
3234 int h = mDatePicker->sizeHint().height() ; 3238 int h = mDatePicker->sizeHint().height() ;
3235 int dw = topLevelWidget()->width(); 3239 int dw = topLevelWidget()->width();
3236 int dh = topLevelWidget()->height(); 3240 int dh = topLevelWidget()->height();
3237 offX = topLevelWidget()->x(); 3241 offX = topLevelWidget()->x();
3238 offY = topLevelWidget()->y(); 3242 offY = topLevelWidget()->y();
3239#else 3243#else
3240 int w =mDatePicker->sizeHint().width() ; 3244 int w =mDatePicker->sizeHint().width() ;
3241 int h = mDatePicker->sizeHint().height() ; 3245 int h = mDatePicker->sizeHint().height() ;
3242 int dw = QApplication::desktop()->width(); 3246 int dw = QApplication::desktop()->width();
3243 int dh = QApplication::desktop()->height(); 3247 int dh = QApplication::desktop()->height();
3244#endif 3248#endif
3245 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 3249 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
3246 mDateFrame->show(); 3250 mDateFrame->show();
3247 } 3251 }
3248} 3252}
3249void CalendarView::showDatePicker( ) 3253void CalendarView::showDatePicker( )
3250{ 3254{
3251 showDatePickerPopup(); 3255 showDatePickerPopup();
3252 mDatePickerMode = 1; 3256 mDatePickerMode = 1;
3253 mDatePicker->setDate( mNavigator->selectedDates().first() ); 3257 mDatePicker->setDate( mNavigator->selectedDates().first() );
3254} 3258}
3255 3259
3256void CalendarView::showEventEditor() 3260void CalendarView::showEventEditor()
3257{ 3261{
3258#ifdef DESKTOP_VERSION 3262#ifdef DESKTOP_VERSION
3259 int x,y,w,h; 3263 int x,y,w,h;
3260 x = mEventEditor->geometry().x(); 3264 x = mEventEditor->geometry().x();
3261 y = mEventEditor->geometry().y(); 3265 y = mEventEditor->geometry().y();
3262 w = mEventEditor->width(); 3266 w = mEventEditor->width();
3263 h = mEventEditor->height(); 3267 h = mEventEditor->height();
3264 mEventEditor->show(); 3268 mEventEditor->show();
3265 mEventEditor->setGeometry(x,y,w,h); 3269 mEventEditor->setGeometry(x,y,w,h);
3266#else 3270#else
3267 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 3271 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
3268 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3272 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3269 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 3273 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
3270 qApp->processEvents(); 3274 qApp->processEvents();
3271 delete mEventEditor; 3275 delete mEventEditor;
3272 mEventEditor = mDialogManager->getEventEditor(); 3276 mEventEditor = mDialogManager->getEventEditor();
3273 topLevelWidget()->setCaption( i18n("") ); 3277 topLevelWidget()->setCaption( i18n("") );
3274 } 3278 }
3275 mEventEditor->showMaximized(); 3279 mEventEditor->showMaximized();
3276#endif 3280#endif
3277} 3281}
3278void CalendarView::showTodoEditor() 3282void CalendarView::showTodoEditor()
3279{ 3283{
3280#ifdef DESKTOP_VERSION 3284#ifdef DESKTOP_VERSION
3281 int x,y,w,h; 3285 int x,y,w,h;
3282 x = mTodoEditor->geometry().x(); 3286 x = mTodoEditor->geometry().x();
3283 y = mTodoEditor->geometry().y(); 3287 y = mTodoEditor->geometry().y();
3284 w = mTodoEditor->width(); 3288 w = mTodoEditor->width();
3285 h = mTodoEditor->height(); 3289 h = mTodoEditor->height();
3286 mTodoEditor->show(); 3290 mTodoEditor->show();
3287 mTodoEditor->setGeometry(x,y,w,h); 3291 mTodoEditor->setGeometry(x,y,w,h);
3288#else 3292#else
3289 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 3293 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
3290 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3294 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3291 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 3295 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
3292 qApp->processEvents(); 3296 qApp->processEvents();
3293 delete mTodoEditor; 3297 delete mTodoEditor;
3294 mTodoEditor = mDialogManager->getTodoEditor(); 3298 mTodoEditor = mDialogManager->getTodoEditor();
3295 topLevelWidget()->setCaption( i18n("") ); 3299 topLevelWidget()->setCaption( i18n("") );
3296 } 3300 }
3297 mTodoEditor->showMaximized(); 3301 mTodoEditor->showMaximized();
3298#endif 3302#endif
3299} 3303}
3300 3304
3301void CalendarView::cloneIncidence() 3305void CalendarView::cloneIncidence()
3302{ 3306{
3303 Incidence *incidence = currentSelection(); 3307 Incidence *incidence = currentSelection();
3304 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3308 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3305 if ( incidence ) { 3309 if ( incidence ) {
3306 cloneIncidence(incidence); 3310 cloneIncidence(incidence);
3307 } 3311 }
3308} 3312}
3309void CalendarView::moveIncidence() 3313void CalendarView::moveIncidence()
3310{ 3314{
3311 Incidence *incidence = currentSelection(); 3315 Incidence *incidence = currentSelection();
3312 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3316 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3313 if ( incidence ) { 3317 if ( incidence ) {
3314 moveIncidence(incidence); 3318 moveIncidence(incidence);
3315 } 3319 }
3316} 3320}
3317void CalendarView::beamIncidence() 3321void CalendarView::beamIncidence()
3318{ 3322{
3319 Incidence *incidence = currentSelection(); 3323 Incidence *incidence = currentSelection();
3320 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3324 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3321 if ( incidence ) { 3325 if ( incidence ) {
3322 beamIncidence(incidence); 3326 beamIncidence(incidence);
3323 } 3327 }
3324} 3328}
3325void CalendarView::toggleCancelIncidence() 3329void CalendarView::toggleCancelIncidence()
3326{ 3330{
3327 Incidence *incidence = currentSelection(); 3331 Incidence *incidence = currentSelection();
3328 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3332 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3329 if ( incidence ) { 3333 if ( incidence ) {
3330 cancelIncidence(incidence); 3334 cancelIncidence(incidence);
3331 } 3335 }
3332} 3336}
3333 3337
3334 3338
3335void CalendarView::cancelIncidence(Incidence * inc ) 3339void CalendarView::cancelIncidence(Incidence * inc )
3336{ 3340{
3337 inc->setCancelled( ! inc->cancelled() ); 3341 inc->setCancelled( ! inc->cancelled() );
3338 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3342 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3339 updateView(); 3343 updateView();
3340} 3344}
3341void CalendarView::cloneIncidence(Incidence * orgInc ) 3345void CalendarView::cloneIncidence(Incidence * orgInc )
3342{ 3346{
3343 Incidence * newInc = orgInc->clone(); 3347 Incidence * newInc = orgInc->clone();
3344 newInc->recreate(); 3348 newInc->recreate();
3345 3349
3346 if ( newInc->typeID() == todoID ) { 3350 if ( newInc->typeID() == todoID ) {
3347 Todo* t = (Todo*) newInc; 3351 Todo* t = (Todo*) newInc;
3348 bool cloneSub = false; 3352 bool cloneSub = false;
3349 if ( orgInc->relations().count() ) { 3353 if ( orgInc->relations().count() ) {
3350 int result = KMessageBox::warningYesNoCancel(this, 3354 int result = KMessageBox::warningYesNoCancel(this,
3351 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ), 3355 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ),
3352 i18n("Todo has subtodos"), 3356 i18n("Todo has subtodos"),
3353 i18n("Yes"), 3357 i18n("Yes"),
3354 i18n("No")); 3358 i18n("No"));
3355 3359
3356 if ( result == KMessageBox::Cancel ) { 3360 if ( result == KMessageBox::Cancel ) {
3357 delete t; 3361 delete t;
3358 return; 3362 return;
3359 } 3363 }
3360 if (result == KMessageBox::Yes) cloneSub = true; 3364 if (result == KMessageBox::Yes) cloneSub = true;
3361 } 3365 }
3362 showTodoEditor(); 3366 showTodoEditor();
3363 mTodoEditor->editTodo( t ); 3367 mTodoEditor->editTodo( t );
3364 if ( mTodoEditor->exec() ) { 3368 if ( mTodoEditor->exec() ) {
3365 if ( cloneSub ) { 3369 if ( cloneSub ) {
3366 orgInc->cloneRelations( t ); 3370 orgInc->cloneRelations( t );
3367 mCalendar->addIncidenceBranch( t ); 3371 mCalendar->addIncidenceBranch( t );
3368 updateView(); 3372 updateView();
3369 3373
3370 } else { 3374 } else {
3371 mCalendar->addTodo( t ); 3375 mCalendar->addTodo( t );
3372 updateView(); 3376 updateView();
3373 } 3377 }
3374 } else { 3378 } else {
3375 delete t; 3379 delete t;
3376 } 3380 }
3377 } 3381 }
3378 else if ( newInc->typeID() == eventID ) { 3382 else if ( newInc->typeID() == eventID ) {
3379 Event* e = (Event*) newInc; 3383 Event* e = (Event*) newInc;
3380 showEventEditor(); 3384 showEventEditor();
3381 mEventEditor->editEvent( e ); 3385 mEventEditor->editEvent( e );
3382 if ( mEventEditor->exec() ) { 3386 if ( mEventEditor->exec() ) {
3383 mCalendar->addEvent( e ); 3387 mCalendar->addEvent( e );
3384 updateView(); 3388 updateView();
3385 } else { 3389 } else {
3386 delete e; 3390 delete e;
3387 } 3391 }
3388 } if ( newInc->typeID() == journalID ) { 3392 } if ( newInc->typeID() == journalID ) {
3389 mCalendar->addJournal( (Journal*) newInc ); 3393 mCalendar->addJournal( (Journal*) newInc );
3390 editJournal( (Journal*) newInc ); 3394 editJournal( (Journal*) newInc );
3391 } 3395 }
3392 setActiveWindow(); 3396 setActiveWindow();
3393} 3397}
3394 3398
3395void CalendarView::newEvent() 3399void CalendarView::newEvent()
3396{ 3400{
3397 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3401 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3398 KOAgendaView *aView = mViewManager->agendaView(); 3402 KOAgendaView *aView = mViewManager->agendaView();
3399 if (aView) { 3403 if (aView) {
3400 if (aView->selectionStart().isValid()) { 3404 if (aView->selectionStart().isValid()) {
3401 if (aView->selectedIsAllDay()) { 3405 if (aView->selectedIsAllDay()) {
3402 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3406 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3403 } else { 3407 } else {
3404 newEvent(aView->selectionStart(),aView->selectionEnd()); 3408 newEvent(aView->selectionStart(),aView->selectionEnd());
3405 } 3409 }
3406 return; 3410 return;
3407 } 3411 }
3408 } 3412 }
3409 3413
3410 QDate date = mNavigator->selectedDates().first(); 3414 QDate date = mNavigator->selectedDates().first();
3411#if 0 3415#if 0
3412 QDateTime current = QDateTime::currentDateTime(); 3416 QDateTime current = QDateTime::currentDateTime();
3413 if ( date <= current.date() ) { 3417 if ( date <= current.date() ) {
3414 int hour = current.time().hour() +1; 3418 int hour = current.time().hour() +1;
3415 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3419 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3416 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3420 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3417 } else 3421 } else
3418#endif 3422#endif
3419 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3423 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3420 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3424 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3421 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3425 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3422} 3426}
3423 3427
3424void CalendarView::newEvent(QDateTime fh) 3428void CalendarView::newEvent(QDateTime fh)
3425{ 3429{
3426 newEvent(fh, 3430 newEvent(fh,
3427 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3431 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3428} 3432}
3429 3433
3430void CalendarView::newEvent(QDate dt) 3434void CalendarView::newEvent(QDate dt)
3431{ 3435{
3432 newEvent(QDateTime(dt, QTime(0,0,0)), 3436 newEvent(QDateTime(dt, QTime(0,0,0)),
3433 QDateTime(dt, QTime(0,0,0)), true); 3437 QDateTime(dt, QTime(0,0,0)), true);
3434} 3438}
3435void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3439void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3436{ 3440{
3437 newEvent(fromHint, toHint, false); 3441 newEvent(fromHint, toHint, false);
3438} 3442}
3439void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3443void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3440{ 3444{
3441 3445
3442 showEventEditor(); 3446 showEventEditor();
3443 mEventEditor->newEvent(fromHint,toHint,allDay); 3447 mEventEditor->newEvent(fromHint,toHint,allDay);
3444 if ( mFilterView->filtersEnabled() ) { 3448 if ( mFilterView->filtersEnabled() ) {
3445 CalFilter *filter = mFilterView->selectedFilter(); 3449 CalFilter *filter = mFilterView->selectedFilter();
3446 if (filter && filter->showCategories()) { 3450 if (filter && filter->showCategories()) {
3447 mEventEditor->setCategories(filter->categoryList().join(",") ); 3451 mEventEditor->setCategories(filter->categoryList().join(",") );
3448 } 3452 }
3449 if ( filter ) 3453 if ( filter )
3450 mEventEditor->setSecrecy( filter->getSecrecy() ); 3454 mEventEditor->setSecrecy( filter->getSecrecy() );
3451 } 3455 }
3452 mEventEditor->exec(); 3456 mEventEditor->exec();
3453 setActiveWindow(); 3457 setActiveWindow();
3454} 3458}
3455void CalendarView::todoAdded(Todo * t) 3459void CalendarView::todoAdded(Todo * t)
3456{ 3460{
3457 3461
3458 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3462 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3459 updateTodoViews(); 3463 updateTodoViews();
3460} 3464}
3461void CalendarView::todoChanged(Todo * t) 3465void CalendarView::todoChanged(Todo * t)
3462{ 3466{
3463 emit todoModified( t, 4 ); 3467 emit todoModified( t, 4 );
3464 // updateTodoViews(); 3468 // updateTodoViews();
3465} 3469}
3466void CalendarView::todoToBeDeleted(Todo *) 3470void CalendarView::todoToBeDeleted(Todo *)
3467{ 3471{
3468 //qDebug("todoToBeDeleted(Todo *) "); 3472 //qDebug("todoToBeDeleted(Todo *) ");
3469 updateTodoViews(); 3473 updateTodoViews();
3470} 3474}
3471void CalendarView::todoDeleted() 3475void CalendarView::todoDeleted()
3472{ 3476{
3473 //qDebug(" todoDeleted()"); 3477 //qDebug(" todoDeleted()");
3474 updateTodoViews(); 3478 updateTodoViews();
3475} 3479}
3476 3480
3477 3481
3478void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3482void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3479{ 3483{
3480 showTodoEditor(); 3484 showTodoEditor();
3481 mTodoEditor->newTodo(dt,0,allday); 3485 mTodoEditor->newTodo(dt,0,allday);
3482 if ( mFilterView->filtersEnabled() ) { 3486 if ( mFilterView->filtersEnabled() ) {
3483 CalFilter *filter = mFilterView->selectedFilter(); 3487 CalFilter *filter = mFilterView->selectedFilter();
3484 if (filter && filter->showCategories()) { 3488 if (filter && filter->showCategories()) {
3485 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3489 mTodoEditor->setCategories(filter->categoryList().join(",") );
3486 } 3490 }
3487 if ( filter ) 3491 if ( filter )
3488 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3492 mTodoEditor->setSecrecy( filter->getSecrecy() );
3489 } 3493 }
3490 mTodoEditor->exec(); 3494 mTodoEditor->exec();
3491 setActiveWindow(); 3495 setActiveWindow();
3492} 3496}
3493 3497
3494void CalendarView::newTodo() 3498void CalendarView::newTodo()
3495{ 3499{
3496 newTodoDateTime( QDateTime(),true ); 3500 newTodoDateTime( QDateTime(),true );
3497} 3501}
3498 3502
3499void CalendarView::newSubTodo() 3503void CalendarView::newSubTodo()
3500{ 3504{
3501 Todo *todo = selectedTodo(); 3505 Todo *todo = selectedTodo();
3502 if ( todo ) newSubTodo( todo ); 3506 if ( todo ) newSubTodo( todo );
3503} 3507}
3504 3508
3505void CalendarView::newSubTodo(Todo *parentEvent) 3509void CalendarView::newSubTodo(Todo *parentEvent)
3506{ 3510{
3507 3511
3508 showTodoEditor(); 3512 showTodoEditor();
3509 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3513 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3510 mTodoEditor->exec(); 3514 mTodoEditor->exec();
3511 setActiveWindow(); 3515 setActiveWindow();
3512} 3516}
3513 3517
3514void CalendarView::newFloatingEvent() 3518void CalendarView::newFloatingEvent()
3515{ 3519{
3516 DateList tmpList = mNavigator->selectedDates(); 3520 DateList tmpList = mNavigator->selectedDates();
3517 QDate date = tmpList.first(); 3521 QDate date = tmpList.first();
3518 3522
3519 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3523 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3520 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3524 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3521} 3525}
3522 3526
3523 3527
3524void CalendarView::editEvent( Event *event ) 3528void CalendarView::editEvent( Event *event )
3525{ 3529{
3526 3530
3527 if ( !event ) return; 3531 if ( !event ) return;
3528 if ( event->isReadOnly() ) { 3532 if ( event->isReadOnly() ) {
3529 showEvent( event ); 3533 showEvent( event );
3530 return; 3534 return;
3531 } 3535 }
3532 showEventEditor(); 3536 showEventEditor();
3533 mEventEditor->editEvent( event , mFlagEditDescription); 3537 mEventEditor->editEvent( event , mFlagEditDescription);
3534 mEventEditor->exec(); 3538 mEventEditor->exec();
3535 setActiveWindow(); 3539 setActiveWindow();
3536 3540
3537} 3541}
3538void CalendarView::editJournal( Journal *jour ) 3542void CalendarView::editJournal( Journal *jour )
3539{ 3543{
3540 if ( !jour ) return; 3544 if ( !jour ) return;
3541 mDialogManager->hideSearchDialog(); 3545 mDialogManager->hideSearchDialog();
3542 mViewManager->showJournalView(); 3546 mViewManager->showJournalView();
3543 mNavigator->slotDaySelect( jour->dtStart().date() ); 3547 mNavigator->slotDaySelect( jour->dtStart().date() );
3544} 3548}
3545void CalendarView::editTodo( Todo *todo ) 3549void CalendarView::editTodo( Todo *todo )
3546{ 3550{
3547 if ( !todo ) return; 3551 if ( !todo ) return;
3548 3552
3549 if ( todo->isReadOnly() ) { 3553 if ( todo->isReadOnly() ) {
3550 showTodo( todo ); 3554 showTodo( todo );
3551 return; 3555 return;
3552 } 3556 }
3553 showTodoEditor(); 3557 showTodoEditor();
3554 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3558 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3555 mTodoEditor->exec(); 3559 mTodoEditor->exec();
3556 setActiveWindow(); 3560 setActiveWindow();
3557 3561
3558} 3562}
3559 3563
3560KOEventViewerDialog* CalendarView::getEventViewerDialog() 3564KOEventViewerDialog* CalendarView::getEventViewerDialog()
3561{ 3565{
3562 if ( !mEventViewerDialog ) { 3566 if ( !mEventViewerDialog ) {
3563 mEventViewerDialog = new KOEventViewerDialog(0); 3567 mEventViewerDialog = new KOEventViewerDialog(0);
3564 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3568 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3565 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3569 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3566 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3570 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3567 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3571 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3568 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3572 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3569 viewManager(), SLOT( showAgendaView( bool ) ) ); 3573 viewManager(), SLOT( showAgendaView( bool ) ) );
3570 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3574 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3571 this, SLOT( slotViewerClosed() ) ); 3575 this, SLOT( slotViewerClosed() ) );
3572 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3576 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3573 this, SLOT( todoChanged(Todo *) ) ); 3577 this, SLOT( todoChanged(Todo *) ) );
3574 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 3578 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
3575 mEventViewerDialog->resize( 640, 480 ); 3579 mEventViewerDialog->resize( 640, 480 );
3576 3580
3577 } 3581 }
3578 return mEventViewerDialog; 3582 return mEventViewerDialog;
3579} 3583}
3580void CalendarView::showEvent(Event *event) 3584void CalendarView::showEvent(Event *event)
3581{ 3585{
3582 getEventViewerDialog()->setEvent(event); 3586 getEventViewerDialog()->setEvent(event);
3583 getEventViewerDialog()->showMe(); 3587 getEventViewerDialog()->showMe();
3584} 3588}
3585 3589
3586void CalendarView::showTodo(Todo *event) 3590void CalendarView::showTodo(Todo *event)
3587{ 3591{
3588 getEventViewerDialog()->setTodo(event); 3592 getEventViewerDialog()->setTodo(event);
3589 getEventViewerDialog()->showMe(); 3593 getEventViewerDialog()->showMe();
3590} 3594}
3591void CalendarView::showJournal( Journal *jour ) 3595void CalendarView::showJournal( Journal *jour )
3592{ 3596{
3593 getEventViewerDialog()->setJournal(jour); 3597 getEventViewerDialog()->setJournal(jour);
3594 getEventViewerDialog()->showMe(); 3598 getEventViewerDialog()->showMe();
3595 3599
3596} 3600}
3597// void CalendarView::todoModified (Todo *event, int changed) 3601// void CalendarView::todoModified (Todo *event, int changed)
3598// { 3602// {
3599// // if (mDialogList.find (event) != mDialogList.end ()) { 3603// // if (mDialogList.find (event) != mDialogList.end ()) {
3600// // kdDebug() << "Todo modified and open" << endl; 3604// // kdDebug() << "Todo modified and open" << endl;
3601// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3605// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3602// // temp->modified (changed); 3606// // temp->modified (changed);
3603 3607
3604// // } 3608// // }
3605 3609
3606// mViewManager->updateView(); 3610// mViewManager->updateView();
3607// } 3611// }
3608 3612
3609void CalendarView::appointment_show() 3613void CalendarView::appointment_show()
3610{ 3614{
3611 Event *anEvent = 0; 3615 Event *anEvent = 0;
3612 3616
3613 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3617 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3614 3618
3615 if (mViewManager->currentView()->isEventView()) { 3619 if (mViewManager->currentView()->isEventView()) {
3616 if ( incidence && incidence->typeID() == eventID ) { 3620 if ( incidence && incidence->typeID() == eventID ) {
3617 anEvent = static_cast<Event *>(incidence); 3621 anEvent = static_cast<Event *>(incidence);
3618 } 3622 }
3619 } 3623 }
3620 3624
3621 if (!anEvent) { 3625 if (!anEvent) {
3622 KNotifyClient::beep(); 3626 KNotifyClient::beep();
3623 return; 3627 return;
3624 } 3628 }
3625 3629
3626 showEvent(anEvent); 3630 showEvent(anEvent);
3627} 3631}
3628 3632
3629void CalendarView::appointment_edit() 3633void CalendarView::appointment_edit()
3630{ 3634{
3631 Event *anEvent = 0; 3635 Event *anEvent = 0;
3632 3636
3633 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3637 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3634 3638
3635 if (mViewManager->currentView()->isEventView()) { 3639 if (mViewManager->currentView()->isEventView()) {
3636 if ( incidence && incidence->typeID() == eventID ) { 3640 if ( incidence && incidence->typeID() == eventID ) {
3637 anEvent = static_cast<Event *>(incidence); 3641 anEvent = static_cast<Event *>(incidence);
3638 } 3642 }
3639 } 3643 }
3640 3644
3641 if (!anEvent) { 3645 if (!anEvent) {
3642 KNotifyClient::beep(); 3646 KNotifyClient::beep();
3643 return; 3647 return;
3644 } 3648 }
3645 3649
3646 editEvent(anEvent); 3650 editEvent(anEvent);
3647} 3651}
3648 3652
3649void CalendarView::appointment_delete() 3653void CalendarView::appointment_delete()
3650{ 3654{
3651 Event *anEvent = 0; 3655 Event *anEvent = 0;
3652 3656
3653 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3657 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3654 3658
3655 if (mViewManager->currentView()->isEventView()) { 3659 if (mViewManager->currentView()->isEventView()) {
3656 if ( incidence && incidence->typeID() == eventID ) { 3660 if ( incidence && incidence->typeID() == eventID ) {
3657 anEvent = static_cast<Event *>(incidence); 3661 anEvent = static_cast<Event *>(incidence);
3658 } 3662 }
3659 } 3663 }
3660 3664
3661 if (!anEvent) { 3665 if (!anEvent) {
3662 KNotifyClient::beep(); 3666 KNotifyClient::beep();
3663 return; 3667 return;
3664 } 3668 }
3665 3669
3666 deleteEvent(anEvent); 3670 deleteEvent(anEvent);
3667} 3671}
3668 3672
3669void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3673void CalendarView::todo_resub( Todo * parent, Todo * sub )
3670{ 3674{
3671 if (!sub) return; 3675 if (!sub) return;
3672 if ( sub->relatedTo() == parent ) 3676 if ( sub->relatedTo() == parent )
3673 return; 3677 return;
3674 sub->setRelatedTo(parent); 3678 sub->setRelatedTo(parent);
3675 sub->updated(); 3679 sub->updated();
3676 setModified(true); 3680 setModified(true);
3677 updateView(); 3681 updateView();
3678} 3682}
3679void CalendarView::todo_unsub(Todo *anTodo ) 3683void CalendarView::todo_unsub(Todo *anTodo )
3680{ 3684{
3681 todo_resub( 0, anTodo ); 3685 todo_resub( 0, anTodo );
3682} 3686}
3683 3687
3684void CalendarView::deleteTodo(Todo *todo) 3688void CalendarView::deleteTodo(Todo *todo)
3685{ 3689{
3686 if (!todo) { 3690 if (!todo) {
3687 KNotifyClient::beep(); 3691 KNotifyClient::beep();
3688 return; 3692 return;
3689 } 3693 }
3690 if (KOPrefs::instance()->mConfirm) { 3694 if (KOPrefs::instance()->mConfirm) {
3691 QString text = KGlobal::formatMessage ( todo->summary(),0 ); 3695 QString text = KGlobal::formatMessage ( todo->summary(),0 );
3692 if (!todo->relations().isEmpty()) { 3696 if (!todo->relations().isEmpty()) {
3693 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3697 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3694 3698
3695 } 3699 }
3696 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) { 3700 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) {
3697 case KMessageBox::Continue: // OK 3701 case KMessageBox::Continue: // OK
3698 bool deleteT = false; 3702 bool deleteT = false;
3699 if (!todo->relations().isEmpty()) { 3703 if (!todo->relations().isEmpty()) {
3700 deleteT = removeCompletedSubTodos( todo ); 3704 deleteT = removeCompletedSubTodos( todo );
3701 } 3705 }
3702 // deleteT == true: todo already deleted in removeCompletedSubTodos 3706 // deleteT == true: todo already deleted in removeCompletedSubTodos
3703 if ( !deleteT ) { 3707 if ( !deleteT ) {
3704 checkExternalId( todo ); 3708 checkExternalId( todo );
3705 calendar()->deleteTodo(todo); 3709 calendar()->deleteTodo(todo);
3706 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3710 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3707 updateView(); 3711 updateView();
3708 } 3712 }
3709 break; 3713 break;
3710 } // switch 3714 } // switch
3711 } else { 3715 } else {
3712 checkExternalId( todo ); 3716 checkExternalId( todo );
3713 mCalendar->deleteTodo(todo); 3717 mCalendar->deleteTodo(todo);
3714 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3718 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3715 updateView(); 3719 updateView();
3716 } 3720 }
3717 3721
3718 emit updateSearchDialog(); 3722 emit updateSearchDialog();
3719} 3723}
3720void CalendarView::deleteJournal(Journal *jour) 3724void CalendarView::deleteJournal(Journal *jour)
3721{ 3725{
3722 if (!jour) { 3726 if (!jour) {
3723 KNotifyClient::beep(); 3727 KNotifyClient::beep();
3724 return; 3728 return;
3725 } 3729 }
3726 if (KOPrefs::instance()->mConfirm) { 3730 if (KOPrefs::instance()->mConfirm) {
3727 3731
3728 QString des; 3732 QString des;
3729 if ( !jour->summary().isEmpty() ) { 3733 if ( !jour->summary().isEmpty() ) {
3730 des = jour->summary(); 3734 des = jour->summary();
3731 } else { 3735 } else {
3732 des = jour->description().left(30); 3736 des = jour->description().left(30);
3733 des = des.simplifyWhiteSpace (); 3737 des = des.simplifyWhiteSpace ();
3734 des.replace (QRegExp ("\\n"),"" ); 3738 des.replace (QRegExp ("\\n"),"" );
3735 des.replace (QRegExp ("\\r"),"" ); 3739 des.replace (QRegExp ("\\r"),"" );
3736 } 3740 }
3737 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) { 3741 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) {
3738 case KMessageBox::Continue: // OK 3742 case KMessageBox::Continue: // OK
3739 calendar()->deleteJournal(jour); 3743 calendar()->deleteJournal(jour);
3740 updateView(); 3744 updateView();
3741 break; 3745 break;
3742 } // switch 3746 } // switch
3743 } else { 3747 } else {
3744 calendar()->deleteJournal(jour);; 3748 calendar()->deleteJournal(jour);;
3745 updateView(); 3749 updateView();
3746 } 3750 }
3747 emit updateSearchDialog(); 3751 emit updateSearchDialog();
3748} 3752}
3749 3753
3750void CalendarView::deleteEvent(Event *anEvent) 3754void CalendarView::deleteEvent(Event *anEvent)
3751{ 3755{
3752 if (!anEvent) { 3756 if (!anEvent) {
3753 KNotifyClient::beep(); 3757 KNotifyClient::beep();
3754 return; 3758 return;
3755 } 3759 }
3756 3760
3757 if (anEvent->recurrence()->doesRecur()) { 3761 if (anEvent->recurrence()->doesRecur()) {
3758 QDate itemDate = mViewManager->currentSelectionDate(); 3762 QDate itemDate = mViewManager->currentSelectionDate();
3759 int km; 3763 int km;
3760 if (!itemDate.isValid()) { 3764 if (!itemDate.isValid()) {
3761 //kdDebug() << "Date Not Valid" << endl; 3765 //kdDebug() << "Date Not Valid" << endl;
3762 if (KOPrefs::instance()->mConfirm) { 3766 if (KOPrefs::instance()->mConfirm) {
3763 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3767 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3764 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3768 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3765 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3769 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3766 if ( km == KMessageBox::Continue ) 3770 if ( km == KMessageBox::Continue )
3767 km = KMessageBox::No; // No = all below 3771 km = KMessageBox::No; // No = all below
3768 } else 3772 } else
3769 km = KMessageBox::No; 3773 km = KMessageBox::No;
3770 } else { 3774 } else {
3771 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3775 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3772 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3776 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3773 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3777 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3774 i18n("KO/Pi Confirmation"),i18n("Current"), 3778 i18n("KO/Pi Confirmation"),i18n("Current"),
3775 i18n("All")); 3779 i18n("All"));
3776 } 3780 }
3777 switch(km) { 3781 switch(km) {
3778 3782
3779 case KMessageBox::No: // Continue // all 3783 case KMessageBox::No: // Continue // all
3780 //qDebug("KMessageBox::No "); 3784 //qDebug("KMessageBox::No ");
3781 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3785 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3782 schedule(Scheduler::Cancel,anEvent); 3786 schedule(Scheduler::Cancel,anEvent);
3783 3787
3784 checkExternalId( anEvent); 3788 checkExternalId( anEvent);
3785 mCalendar->deleteEvent(anEvent); 3789 mCalendar->deleteEvent(anEvent);
3786 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3790 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3787 break; 3791 break;
3788 3792
3789 // Disabled because it does not work 3793 // Disabled because it does not work
3790 //#if 0 3794 //#if 0
3791 case KMessageBox::Yes: // just this one 3795 case KMessageBox::Yes: // just this one
3792 //QDate qd = mNavigator->selectedDates().first(); 3796 //QDate qd = mNavigator->selectedDates().first();
3793 //if (!qd.isValid()) { 3797 //if (!qd.isValid()) {
3794 // kdDebug() << "no date selected, or invalid date" << endl; 3798 // kdDebug() << "no date selected, or invalid date" << endl;
3795 // KNotifyClient::beep(); 3799 // KNotifyClient::beep();
3796 // return; 3800 // return;
3797 //} 3801 //}
3798 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3802 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3799 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3803 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3800 anEvent->addExDate(itemDate); 3804 anEvent->addExDate(itemDate);
3801 int duration = anEvent->recurrence()->duration(); 3805 int duration = anEvent->recurrence()->duration();
3802 if ( duration > 0 ) { 3806 if ( duration > 0 ) {
3803 anEvent->recurrence()->setDuration( duration - 1 ); 3807 anEvent->recurrence()->setDuration( duration - 1 );