File r905610.diff of Package kdepim4
Subject: korganizer: fix new journal is set to date of the first day of the week/month
From: wstephenson@suse.de
Bug: kde#170634
Patch-upstream: 905610
--- korganizer/calendarview.h (revision 905609)
+++ korganizer/calendarview.h (revision 905610)
@@ -592,30 +592,27 @@ class KORGANIZERPRIVATE_EXPORT CalendarV
void showDates( const KCal::DateList & );
public:
- // show a standard warning
- // returns KMsgBox::yesNoCancel()
int msgCalModified();
- /** Adapt navigation units corresponding to step size of navigation of the
- * current view.
- */
+ /**
+ Adapts navigation units according to the current view's navigation step size.
+ */
void adaptNavigationUnits();
- //Attendee* getYourAttendee( Event *event );
-
protected:
void setIncidenceChanger( IncidenceChangerBase *changer );
-// // returns KMsgBox::OKCancel()
int msgItemDelete( Incidence *incidence );
Todo *selectedTodo();
void warningChangeFailed( Incidence * );
void checkForFilteredChange( Incidence *incidence );
- /** Adjust the given date/times by valid defaults (selection or configured
- defaults, if invalid values are given) and allow the view to adjust the
- type. */
+
+ /**
+ Adjust the given date/times by valid defaults (selection or configured
+ defaults, if invalid values are given) and allow the view to adjust the type.
+ */
void dateTimesForNewEvent( QDateTime &startDt, QDateTime &endDt, bool &allDay );
KOEventEditor *newEventEditor( const QDateTime &startDtParam=QDateTime(),
const QDateTime &endDtParam=QDateTime(),
@@ -626,9 +623,15 @@ class KORGANIZERPRIVATE_EXPORT CalendarV
private:
void init();
+ /**
+ Returns the best guess at the current active date in the view.
+ */
+ QDate activeDate();
+
void createPrinter();
void calendarModified( bool, Calendar * );
+
// Helper function for purgeCompleted that recursively purges a todo and
// its subitems. If it cannot delete a completed todo (because it has
// uncompleted subitems), notAllPurged is set to true.
@@ -673,7 +676,7 @@ class KORGANIZERPRIVATE_EXPORT CalendarV
QMap<Incidence*,KOIncidenceEditor*> mDialogList;
KOrg::IncidenceChangerBase *mChanger;
- QList<int> mMainSplitterSizes; // temporary store for main splitter sizes while the left frame is hidden
+ QList<int> mMainSplitterSizes; // temp store for main splitter sizes while left frame is hidden
bool mSplitterSizesValid;
};
--- korganizer/calendarview.cpp (revision 905609)
+++ korganizer/calendarview.cpp (revision 905610)
@@ -328,6 +328,29 @@ KOIncidenceEditor *CalendarView::editorD
}
}
+QDate CalendarView::activeDate()
+{
+ KOrg::BaseView *curView = mViewManager->currentView();
+ if ( curView ) {
+ // Only the agenda view has a selectionStart (at this time)
+ KOAgendaView *aView = mViewManager->agendaView();
+ if ( curView == aView && aView->selectionStart().isValid() ) {
+ if ( aView->selectionStart().isValid() ) {
+ return aView->selectionStart().date();
+ }
+ }
+ // Try the view's selectedDates()
+ if ( !curView->selectedDates().isEmpty() ) {
+ if ( curView->selectedDates().first().isValid() ) {
+ return curView->selectedDates().first();
+ }
+ }
+ }
+
+ // When all else fails, use the navigator start date.
+ return mNavigator->selectedDates().first();
+}
+
QDate CalendarView::startDate()
{
DateList dates = mNavigator->selectedDates();
@@ -909,10 +932,11 @@ void CalendarView::edit_options()
mDialogManager->showOptionsDialog();
}
-void CalendarView::dateTimesForNewEvent( QDateTime &startDt, QDateTime &endDt, bool &allDay )
+void CalendarView::dateTimesForNewEvent( QDateTime &startDt, QDateTime &endDt,
+ bool &allDay )
{
if ( !startDt.isValid() ) {
- startDt.setDate( mNavigator->selectedDates().first() );
+ startDt.setDate( activeDate() );
startDt.setTime( KOPrefs::instance()->mStartTime.time() );
}
if ( !endDt.isValid() ) {
@@ -925,11 +949,13 @@ void CalendarView::dateTimesForNewEvent(
}
KOEventEditor *CalendarView::newEventEditor( const QDateTime &startDtParam,
- const QDateTime &endDtParam, bool allDayParam )
+ const QDateTime &endDtParam,
+ bool allDayParam )
{
- // let the current view change the default start/end datetime
+ // Let the current view change the default start/end datetime
bool allDay = allDayParam;
QDateTime startDt( startDtParam ), endDt( endDtParam );
+
// Adjust the start/end date times (i.e. replace invalid values by defaults,
// and let the view adjust the type.
dateTimesForNewEvent( startDt, endDt, allDay );
@@ -972,6 +998,7 @@ void CalendarView::newEvent( const QStri
{
KOEventEditor *eventEditor = newEventEditor();
eventEditor->setTexts( summary, description );
+
// if attach or attendee list is empty, these methods don't do anything, so
// it's save to call them in every case
eventEditor->addAttachments( attachments, attachmentMimetypes, inlineAttachment );
@@ -1000,7 +1027,7 @@ void CalendarView::newTodo()
connectIncidenceEditor( todoEditor );
todoEditor->newTodo();
if ( mViewManager->currentView()->isEventView() ) {
- dtDue.setDate( mNavigator->selectedDates().first() );
+ dtDue.setDate( activeDate() );
QDateTime dtDummy = QDateTime::currentDateTime();
mViewManager->currentView()->
eventDurationHint( dtDue, dtDummy, allday );
@@ -1020,8 +1047,7 @@ void CalendarView::newTodo( const QDate
void CalendarView::newJournal()
{
- kDebug();
- newJournal( QString(), QDate() );
+ newJournal( QString(), activeDate() );
}
void CalendarView::newJournal( const QDate &date )
@@ -1036,7 +1062,7 @@ void CalendarView::newJournal( const QSt
connectIncidenceEditor( journalEditor );
journalEditor->newJournal();
if ( !journalDate.isValid() ) {
- journalDate = mNavigator->selectedDates().first();
+ journalDate = activeDate();
}
journalEditor->setDate( journalDate );
if ( !text.isEmpty() ) {
@@ -1066,9 +1092,7 @@ void CalendarView::newSubTodo( Todo *par
void CalendarView::newFloatingEvent()
{
- DateList tmpList = mNavigator->selectedDates();
- QDate date = tmpList.first();
-
+ QDate date = activeDate();
newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
QDateTime( date, QTime( 12, 0, 0 ) ), true );
}
Index: korganizer/calendarview.h
===================================================================
Index: korganizer/calendarview.cpp
===================================================================