author | zautrix <zautrix> | 2005-06-15 14:00:35 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-15 14:00:35 (UTC) |
commit | 40fa3e374fd96c0cb8925a1c3c46d40e1ea2b111 (patch) (unidiff) | |
tree | d28170ea94bbf7f1c7e90ef1fe7cf3807a847fed | |
parent | 13c00953a9d521873b03f861e54e83e33b30bc96 (diff) | |
download | kdepimpi-40fa3e374fd96c0cb8925a1c3c46d40e1ea2b111.zip kdepimpi-40fa3e374fd96c0cb8925a1c3c46d40e1ea2b111.tar.gz kdepimpi-40fa3e374fd96c0cb8925a1c3c46d40e1ea2b111.tar.bz2 |
fixes
-rw-r--r-- | korganizer/calendarview.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 1338224..377a66f 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -1810,114 +1810,114 @@ bool CalendarView::importQtopia( const QString &categories, | |||
1810 | getEventViewerDialog()->setSyncMode( false ); | 1810 | getEventViewerDialog()->setSyncMode( false ); |
1811 | qApp->processEvents(); | 1811 | qApp->processEvents(); |
1812 | if ( syncOK ) { | 1812 | if ( syncOK ) { |
1813 | if ( mSyncManager->mWriteBackFile ) | 1813 | if ( mSyncManager->mWriteBackFile ) |
1814 | { | 1814 | { |
1815 | // write back XML file | 1815 | // write back XML file |
1816 | 1816 | ||
1817 | } | 1817 | } |
1818 | setModified( true ); | 1818 | setModified( true ); |
1819 | } | 1819 | } |
1820 | } else { | 1820 | } else { |
1821 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; | 1821 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; |
1822 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), | 1822 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), |
1823 | question, i18n("Ok")) ; | 1823 | question, i18n("Ok")) ; |
1824 | } | 1824 | } |
1825 | delete calendar; | 1825 | delete calendar; |
1826 | updateView(); | 1826 | updateView(); |
1827 | return syncOK; | 1827 | return syncOK; |
1828 | 1828 | ||
1829 | 1829 | ||
1830 | #endif | 1830 | #endif |
1831 | 1831 | ||
1832 | } | 1832 | } |
1833 | 1833 | ||
1834 | void CalendarView::setSyncEventsReadOnly() | 1834 | void CalendarView::setSyncEventsReadOnly() |
1835 | { | 1835 | { |
1836 | Event * ev; | 1836 | Event * ev; |
1837 | QPtrList<Event> eL = mCalendar->rawEvents(); | 1837 | QPtrList<Event> eL = mCalendar->rawEvents(); |
1838 | ev = eL.first(); | 1838 | ev = eL.first(); |
1839 | while ( ev ) { | 1839 | while ( ev ) { |
1840 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 1840 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
1841 | ev->setReadOnly( true ); | 1841 | ev->setReadOnly( true ); |
1842 | ev = eL.next(); | 1842 | ev = eL.next(); |
1843 | } | 1843 | } |
1844 | } | 1844 | } |
1845 | 1845 | ||
1846 | bool CalendarView::loadCalendars() | 1846 | bool CalendarView::loadCalendars() |
1847 | { | 1847 | { |
1848 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 1848 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
1849 | KopiCalendarFile * cal = calendars.first(); | 1849 | KopiCalendarFile * cal = calendars.first(); |
1850 | mCalendar->setDefaultCalendar( 1 ); | 1850 | mCalendar->setDefaultCalendar( 1 ); |
1851 | openCalendar( MainWindow::defaultFileName(), false ); | 1851 | openCalendar( MainWindow::defaultFileName(), false ); |
1852 | cal = calendars.next(); | 1852 | cal = calendars.next(); |
1853 | while ( cal ) { | 1853 | while ( cal ) { |
1854 | addCalendar( cal ); | 1854 | addCalendar( cal ); |
1855 | cal = calendars.next(); | 1855 | cal = calendars.next(); |
1856 | } | 1856 | } |
1857 | restoreCalendarSettings(); | 1857 | restoreCalendarSettings(); |
1858 | mCalendar->reInitAlarmSettings(); | ||
1859 | setSyncEventsReadOnly(); | ||
1860 | updateUnmanagedViews(); | ||
1861 | updateView(); | ||
1862 | return true; | 1858 | return true; |
1863 | } | 1859 | } |
1864 | bool CalendarView::restoreCalendarSettings() | 1860 | bool CalendarView::restoreCalendarSettings() |
1865 | { | 1861 | { |
1866 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 1862 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
1867 | KopiCalendarFile * cal = calendars.first(); | 1863 | KopiCalendarFile * cal = calendars.first(); |
1868 | while ( cal ) { | 1864 | while ( cal ) { |
1869 | mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); | 1865 | mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); |
1870 | mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); | 1866 | mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); |
1871 | mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); | 1867 | mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); |
1872 | if ( cal->isStandard ) | 1868 | if ( cal->isStandard ) |
1873 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 1869 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
1874 | cal = calendars.next(); | 1870 | cal = calendars.next(); |
1875 | } | 1871 | } |
1872 | setSyncEventsReadOnly(); | ||
1873 | mCalendar->reInitAlarmSettings(); | ||
1874 | updateUnmanagedViews(); | ||
1875 | updateView(); | ||
1876 | return true; | 1876 | return true; |
1877 | } | 1877 | } |
1878 | void CalendarView::addCalendarId( int id ) | 1878 | void CalendarView::addCalendarId( int id ) |
1879 | { | 1879 | { |
1880 | KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); | 1880 | KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); |
1881 | addCalendar( cal ); | 1881 | addCalendar( cal ); |
1882 | } | 1882 | } |
1883 | bool CalendarView::addCalendar( KopiCalendarFile * cal ) | 1883 | bool CalendarView::addCalendar( KopiCalendarFile * cal ) |
1884 | { | 1884 | { |
1885 | cal->mErrorOnLoad = false; | 1885 | cal->mErrorOnLoad = false; |
1886 | if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { | 1886 | if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { |
1887 | cal->mLoadDt = QDateTime::currentDateTime(); | 1887 | cal->mLoadDt = QDateTime::currentDateTime(); |
1888 | return true; | 1888 | return true; |
1889 | } | 1889 | } |
1890 | qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); | 1890 | qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); |
1891 | KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); | 1891 | KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); |
1892 | cal->mErrorOnLoad = true; | 1892 | cal->mErrorOnLoad = true; |
1893 | return false; | 1893 | return false; |
1894 | } | 1894 | } |
1895 | bool CalendarView::openCalendar(QString filename, bool merge) | 1895 | bool CalendarView::openCalendar(QString filename, bool merge) |
1896 | { | 1896 | { |
1897 | 1897 | ||
1898 | if (filename.isEmpty()) { | 1898 | if (filename.isEmpty()) { |
1899 | return false; | 1899 | return false; |
1900 | } | 1900 | } |
1901 | 1901 | ||
1902 | if (!QFile::exists(filename)) { | 1902 | if (!QFile::exists(filename)) { |
1903 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); | 1903 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); |
1904 | return false; | 1904 | return false; |
1905 | } | 1905 | } |
1906 | 1906 | ||
1907 | globalFlagBlockAgenda = 1; | 1907 | globalFlagBlockAgenda = 1; |
1908 | clearAllViews(); | 1908 | clearAllViews(); |
1909 | if (!merge) { | 1909 | if (!merge) { |
1910 | mViewManager->setDocumentId( filename ); | 1910 | mViewManager->setDocumentId( filename ); |
1911 | mCalendar->close(); | 1911 | mCalendar->close(); |
1912 | } | 1912 | } |
1913 | mStorage->setFileName( filename ); | 1913 | mStorage->setFileName( filename ); |
1914 | 1914 | ||
1915 | if ( mStorage->load() ) { | 1915 | if ( mStorage->load() ) { |
1916 | if ( merge ) ;//setModified( true ); | 1916 | if ( merge ) ;//setModified( true ); |
1917 | else { | 1917 | else { |
1918 | //setModified( true ); | 1918 | //setModified( true ); |
1919 | mViewManager->setDocumentId( filename ); | 1919 | mViewManager->setDocumentId( filename ); |
1920 | mDialogManager->setDocumentId( filename ); | 1920 | mDialogManager->setDocumentId( filename ); |
1921 | mTodoList->setDocumentId( filename ); | 1921 | mTodoList->setDocumentId( filename ); |
1922 | } | 1922 | } |
1923 | globalFlagBlockAgenda = 2; | 1923 | globalFlagBlockAgenda = 2; |
@@ -1950,125 +1950,128 @@ bool CalendarView::openCalendar(QString filename, bool merge) | |||
1950 | 1950 | ||
1951 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); | 1951 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); |
1952 | globalFlagBlockAgenda = 2; | 1952 | globalFlagBlockAgenda = 2; |
1953 | mCalendar->reInitAlarmSettings(); | 1953 | mCalendar->reInitAlarmSettings(); |
1954 | setSyncEventsReadOnly(); | 1954 | setSyncEventsReadOnly(); |
1955 | updateUnmanagedViews(); | 1955 | updateUnmanagedViews(); |
1956 | updateView(); | 1956 | updateView(); |
1957 | } | 1957 | } |
1958 | return false; | 1958 | return false; |
1959 | } | 1959 | } |
1960 | void CalendarView::showOpenError() | 1960 | void CalendarView::showOpenError() |
1961 | { | 1961 | { |
1962 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); | 1962 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); |
1963 | } | 1963 | } |
1964 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 1964 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
1965 | { | 1965 | { |
1966 | loadedFileVersion = dt; | 1966 | loadedFileVersion = dt; |
1967 | } | 1967 | } |
1968 | bool CalendarView::checkFileChanged(QString fn) | 1968 | bool CalendarView::checkFileChanged(QString fn) |
1969 | { | 1969 | { |
1970 | QFileInfo finf ( fn ); | 1970 | QFileInfo finf ( fn ); |
1971 | if ( !finf.exists() ) | 1971 | if ( !finf.exists() ) |
1972 | return true; | 1972 | return true; |
1973 | QDateTime dt = finf.lastModified (); | 1973 | QDateTime dt = finf.lastModified (); |
1974 | if ( dt <= loadedFileVersion ) | 1974 | if ( dt <= loadedFileVersion ) |
1975 | return false; | 1975 | return false; |
1976 | return true; | 1976 | return true; |
1977 | 1977 | ||
1978 | } | 1978 | } |
1979 | void CalendarView::watchSavedFile() | 1979 | void CalendarView::watchSavedFile() |
1980 | { | 1980 | { |
1981 | QFileInfo finf ( MainWindow::defaultFileName()); | 1981 | QFileInfo finf ( MainWindow::defaultFileName()); |
1982 | if ( !finf.exists() ) | 1982 | if ( !finf.exists() ) |
1983 | return; | 1983 | return; |
1984 | QDateTime dt = finf.lastModified (); | 1984 | QDateTime dt = finf.lastModified (); |
1985 | if ( dt < loadedFileVersion ) { | 1985 | if ( dt < loadedFileVersion ) { |
1986 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); | 1986 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); |
1987 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); | 1987 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); |
1988 | return; | 1988 | return; |
1989 | } | 1989 | } |
1990 | loadedFileVersion = dt; | 1990 | loadedFileVersion = dt; |
1991 | } | 1991 | } |
1992 | bool CalendarView::checkAllFileVersions() | 1992 | bool CalendarView::checkAllFileVersions() |
1993 | { | 1993 | { |
1994 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 1994 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
1995 | KopiCalendarFile * cal = calendars.first(); | 1995 | KopiCalendarFile * cal = calendars.first(); |
1996 | mCalendar->setDefaultCalendar( 1 ); | 1996 | mCalendar->setDefaultCalendar( 1 ); |
1997 | mCalendar->setDefaultCalendarEnabledOnly(); | 1997 | mCalendar->setDefaultCalendarEnabledOnly(); |
1998 | if ( !checkFileVersion(MainWindow::defaultFileName())) | 1998 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { |
1999 | if ( !checkFileVersion(MainWindow::defaultFileName())) { | ||
2000 | restoreCalendarSettings(); | ||
1999 | return false; | 2001 | return false; |
2002 | } | ||
2003 | } | ||
2000 | cal = calendars.next(); | 2004 | cal = calendars.next(); |
2001 | QDateTime storeTemp = loadedFileVersion; | 2005 | QDateTime storeTemp = loadedFileVersion; |
2002 | while ( cal ) { | 2006 | while ( cal ) { |
2003 | if ( !cal->mErrorOnLoad ) { | 2007 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { |
2004 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 2008 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
2005 | mCalendar->setDefaultCalendarEnabledOnly(); | 2009 | mCalendar->setDefaultCalendarEnabledOnly(); |
2006 | loadedFileVersion = cal->mLoadDt.addSecs( 15 ); | 2010 | loadedFileVersion = cal->mLoadDt.addSecs( 15 ); |
2007 | if ( !checkFileVersion(cal->mFileName )) { | 2011 | if ( !checkFileVersion(cal->mFileName )) { |
2008 | loadedFileVersion = storeTemp; | 2012 | loadedFileVersion = storeTemp; |
2009 | updateView(); | 2013 | restoreCalendarSettings(); |
2010 | return false; | 2014 | return false; |
2011 | } | 2015 | } |
2012 | } | 2016 | } |
2013 | cal = calendars.next(); | 2017 | cal = calendars.next(); |
2014 | } | 2018 | } |
2015 | loadedFileVersion = storeTemp; | 2019 | loadedFileVersion = storeTemp; |
2016 | updateView(); | ||
2017 | return true; | 2020 | return true; |
2018 | } | 2021 | } |
2019 | bool CalendarView::checkFileVersion(QString fn) | 2022 | bool CalendarView::checkFileVersion(QString fn) |
2020 | { | 2023 | { |
2021 | QFileInfo finf ( fn ); | 2024 | QFileInfo finf ( fn ); |
2022 | if ( !finf.exists() ) | 2025 | if ( !finf.exists() ) |
2023 | return true; | 2026 | return true; |
2024 | QDateTime dt = finf.lastModified (); | 2027 | QDateTime dt = finf.lastModified (); |
2025 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); | 2028 | qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); |
2026 | //qDebug("file on disk version %s",dt.toString().latin1()); | 2029 | qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); |
2027 | if ( dt <= loadedFileVersion ) | 2030 | if ( dt <= loadedFileVersion ) |
2028 | return true; | 2031 | return true; |
2029 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on 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(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , | 2032 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on 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(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , |
2030 | i18n("KO/Pi Warning"),i18n("Overwrite"), | 2033 | i18n("KO/Pi Warning"),i18n("Overwrite"), |
2031 | i18n("Sync+save")); | 2034 | i18n("Sync+save")); |
2032 | 2035 | ||
2033 | if ( km == KMessageBox::Cancel ) | 2036 | if ( km == KMessageBox::Cancel ) |
2034 | return false; | 2037 | return false; |
2035 | if ( km == KMessageBox::Yes ) | 2038 | if ( km == KMessageBox::Yes ) |
2036 | return true; | 2039 | return true; |
2037 | 2040 | ||
2038 | setSyncDevice("deleteaftersync" ); | 2041 | setSyncDevice("deleteaftersync" ); |
2039 | mSyncManager->mAskForPreferences = true; | 2042 | mSyncManager->mAskForPreferences = true; |
2040 | mSyncManager->mSyncAlgoPrefs = 3; | 2043 | mSyncManager->mSyncAlgoPrefs = 3; |
2041 | mSyncManager->mWriteBackFile = false; | 2044 | mSyncManager->mWriteBackFile = false; |
2042 | mSyncManager->mWriteBackExistingOnly = false; | 2045 | mSyncManager->mWriteBackExistingOnly = false; |
2043 | mSyncManager->mShowSyncSummary = false; | 2046 | mSyncManager->mShowSyncSummary = false; |
2044 | syncCalendar( fn, 3 ); | 2047 | syncCalendar( fn, 3 ); |
2045 | Event * e = getLastSyncEvent(); | 2048 | Event * e = getLastSyncEvent(); |
2046 | if ( e ) | 2049 | if ( e ) |
2047 | mCalendar->deleteEvent( e ); | 2050 | mCalendar->deleteEvent( e ); |
2048 | return true; | 2051 | return true; |
2049 | } | 2052 | } |
2050 | bool CalendarView::saveCalendars() | 2053 | bool CalendarView::saveCalendars() |
2051 | { | 2054 | { |
2052 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 2055 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
2053 | KopiCalendarFile * cal = calendars.first(); | 2056 | KopiCalendarFile * cal = calendars.first(); |
2054 | mCalendar->setDefaultCalendar( 1 ); | 2057 | mCalendar->setDefaultCalendar( 1 ); |
2055 | mCalendar->setDefaultCalendarEnabledOnly(); | 2058 | mCalendar->setDefaultCalendarEnabledOnly(); |
2056 | saveCalendar( MainWindow::defaultFileName() ); | 2059 | saveCalendar( MainWindow::defaultFileName() ); |
2057 | cal = calendars.next(); | 2060 | cal = calendars.next(); |
2058 | while ( cal ) { | 2061 | while ( cal ) { |
2059 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { | 2062 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { |
2060 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 2063 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
2061 | mCalendar->setDefaultCalendarEnabledOnly(); | 2064 | mCalendar->setDefaultCalendarEnabledOnly(); |
2062 | if ( saveCalendar( cal->mFileName ) ) | 2065 | if ( saveCalendar( cal->mFileName ) ) |
2063 | cal->mLoadDt = QDateTime::currentDateTime(); | 2066 | cal->mLoadDt = QDateTime::currentDateTime(); |
2064 | } | 2067 | } |
2065 | cal = calendars.next(); | 2068 | cal = calendars.next(); |
2066 | } | 2069 | } |
2067 | restoreCalendarSettings(); | 2070 | restoreCalendarSettings(); |
2068 | return true; | 2071 | return true; |
2069 | } | 2072 | } |
2070 | bool CalendarView::saveCalendar( QString filename ) | 2073 | bool CalendarView::saveCalendar( QString filename ) |
2071 | { | 2074 | { |
2072 | 2075 | ||
2073 | // Store back all unsaved data into calendar object | 2076 | // Store back all unsaved data into calendar object |
2074 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); | 2077 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); |