[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    [Kde-pim] Bug 128435 - patch and request for comment
From:       Dima Kagan <dima_kagan () tut ! by>
Date:       2007-02-20 19:59:54
Message-ID: 45DB533A.30500 () tut ! by
[Download RAW message or body]

Hi, everyone!

As a first contribution to KDE, I decided to nail down a bug that has 
been bothering me the most.

Now, for details. The original code seems to ignore entirely the 
workdays settings in the configuration and instead implements a logic, 
assuming Monday is first workday and workweek is always 5 days. Both 
aren't always true, of course.
My patch solves these problems. The workday settings are read from the 
configuration and the code works correctly with any day as week start 
day in Regional Settings and any given selection of workdays in 
Korganizer's configuration.

There is one minor issue, which I've yet to figure out.
The "Work Week View" always insists on displaying consequent workdays, 
even when it contradicts user selection.
For example, I select Monday, Tuesday, Thursday and Friday as workdays.
The "Work Week View" will display Monday through Friday(including 
Wednesday) as work days. I know, my code doesn't cause these since I set 
mSelectedDays specifically to workdays selected in configuration.
This is a minor issue though, and I'm hoping my patch will make it into 
the tree and the next stable release, because it almost completely 
solves a very annoying issue which makes korganizer unusable in some 
situations.

I've attached the diff against the 3.5 branch tree. I tried to keep up 
with the coding style as much as possible.

Please, post your feedback and ideas about the above mentioned issue.
This is my first submission, so any newbie tips will be appreciated.

Regards,
Dmitry Kagan


["korganizer.diff" (text/plain)]

Index: korganizer/koglobals.cpp
===================================================================
--- korganizer/koglobals.cpp	(revision 635723)
+++ korganizer/koglobals.cpp	(working copy)
@@ -172,6 +172,11 @@
   return !nonWorkDay;
 }
 
+int KOGlobals::getWorkWeekMask()
+{
+  return KOPrefs::instance()->mWorkWeekMask;
+}
+
 void KOGlobals::setHolidays( KHolidays *h )
 {
   delete mHolidays;
Index: korganizer/datenavigator.cpp
===================================================================
--- korganizer/datenavigator.cpp	(revision 635723)
+++ korganizer/datenavigator.cpp	(working copy)
@@ -101,8 +101,7 @@
 {
   int dateCount = mSelectedDates.count();
   bool weekStart = ( weekDay == KGlobal::locale()->weekStartDay() );
-  if ( weekDay == 1 && dateCount == 5 ) selectWorkWeek( d );
-  else if ( weekStart && dateCount == 7 ) selectWeek( d );
+  if ( weekStart && dateCount == 7 ) selectWeek( d );
   else selectDates( d, dateCount );
 }
 
@@ -133,16 +132,26 @@
 
 void DateNavigator::selectWorkWeek( const QDate &d )
 {
+  int weekStart = KGlobal::locale()->weekStartDay();
+ 
   int dayOfWeek = KOGlobals::self()->calendarSystem()->dayOfWeek( d );
 
-  QDate firstDate = d.addDays( 1 - dayOfWeek );
+  QDate currentDate = d.addDays( weekStart - dayOfWeek );
 
-  int weekStart = KGlobal::locale()->weekStartDay();
-  if ( weekStart != 1 && dayOfWeek >= weekStart ) {
-    firstDate = firstDate.addDays( 7 );
+  if ( weekStart != 1 && dayOfWeek < weekStart ) {
+    currentDate = currentDate.addDays( -7 );
   }
 
-  selectDates( firstDate, 5 );
+  mSelectedDates.clear();
+  int mask = KOGlobals::self()->getWorkWeekMask();
+
+  for ( int i = 0; i < 7; ++i ) {
+    if( (1<< ((i + weekStart + 6) % 7)) & (mask) ) {
+	mSelectedDates.append(currentDate.addDays(i));
+    }
+  }
+  
+  emitSelected();
 }
 
 void DateNavigator::selectToday()
@@ -151,8 +160,7 @@
 
   int dateCount = mSelectedDates.count();
 
-  if ( dateCount == 5 ) selectWorkWeek( d );
-  else if ( dateCount == 7 ) selectWeek( d );
+  if ( dateCount == 7 ) selectWeek( d );
   else selectDates( d, dateCount );
 }
 
Index: korganizer/koglobals.h
===================================================================
--- korganizer/koglobals.h	(revision 635723)
+++ korganizer/koglobals.h	(working copy)
@@ -61,7 +61,7 @@
 
     QStringList holiday( const QDate & );
     bool isWorkDay( const QDate & );
-
+    int getWorkWeekMask();
     /**
        Set which holidays the user wants to use.
        @param h a KHolidays object initialized with the desired locale.
Index: korganizer/calendarview.cpp
===================================================================
--- korganizer/calendarview.cpp	(revision 635723)
+++ korganizer/calendarview.cpp	(working copy)
@@ -494,9 +494,8 @@
 
   config->setGroup( "Views" );
   int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
-  if ( dateCount == 5 ) mNavigator->selectWorkWeek();
-  else if ( dateCount == 7 ) mNavigator->selectWeek();
-  else mNavigator->selectDates( dateCount );
+  if ( dateCount == 7 ) mNavigator->selectWeek();
+  else mNavigator->selectDates( mNavigator->selectedDates().first(), dateCount );
 }
 
 


_______________________________________________
kde-pim mailing list
kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic