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

List:       kde-pim
Subject:    [Kde-pim] [PATCH] Port koprefsdialog to new generic timezone support
From:       Shaheed <srhaque () iee ! org>
Date:       2005-07-25 18:14:57
Message-ID: 200507251915.07478.srhaque () iee ! org
[Download RAW message or body]

Retry...

----------  Forwarded Message  ----------

Subject: [PATCH] Port koprefsdialog to new generic timezone support
Date: Sunday 24 July 2005 15:48
From: Shaheed <srhaque@iee.org>
To: kde-pim@mail.kde.org

Hi all,

Here is a patch to port koprefsdialog to the new generic timezone support.

You will note that the QComboBox has been replaced with a (derivation of)
KListView: this is deliberate and intended to eventually allow for multiple
timezones to be selected, a primary and one or more secondaries.

The idea is to be able to display the secondary timezone(s) in some manner on
the koagendaview so that, for example, someone corresponding with a colleague
in a different timezone can see both "clocks" simultaneously.

Comments?

Thanks, Shaheed

P.S. Please CC me on responses

-------------------------------------------------------

["timezone.diff" (text/x-diff)]

Index: koprefsdialog.cpp
===================================================================
--- koprefsdialog.cpp	(revision 437945)
+++ koprefsdialog.cpp	(working copy)
@@ -32,6 +32,7 @@
 #include <qfile.h>
 #include <qcombobox.h>
 #include <qhbox.h>
+#include <qvbox.h>
 #include <qspinbox.h>
 #include <qcheckbox.h>
 #include <qradiobutton.h>
@@ -55,15 +56,10 @@
 #include <libkcal/calendarresources.h>
 #include <kstandarddirs.h>
 #include <ksimpleconfig.h>
+#include <ktimezones.h>
+#include <ktimezonewidget.h>
 #include <kholidays.h>
 
-#if defined(USE_SOLARIS)
-#include <sys/param.h>
-
-#define ZONEINFODIR    "/usr/share/lib/zoneinfo"
-#define INITFILE       "/etc/default/init"
-#endif
-
 #include "koprefs.h"
 
 #include "koprefsdialog.h"
@@ -219,99 +215,22 @@
       QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
       topLayout->setSpacing( KDialog::spacingHint() );
 
-      QHBox *timeZoneBox = new QHBox( topFrame );
+      QVBox *timeZoneBox = new QVBox( topFrame );
       topLayout->addMultiCellWidget( timeZoneBox, 0, 0, 0, 1 );
 
       QLabel *timeZoneLabel = new QLabel( i18n("Timezone:"), timeZoneBox );
       QString whatsThis = i18n( "Select your timezone from the list of "
-                                "locations on this drop down box. If your city "
+                                "locations. If your city "
                                 "is not listed, select one which shares the "
                                 "same timezone. KOrganizer will automatically "
                                 "adjust for daylight savings." );
       QWhatsThis::add( timeZoneLabel, whatsThis );
-      mTimeZoneCombo = new QComboBox( timeZoneBox );
 
-      connect( mTimeZoneCombo, SIGNAL( activated( int ) ),
+      mTimeZoneList = new KTimezoneWidget( timeZoneBox );
+      connect( mTimeZoneList, SIGNAL( selectionChanged() ),
                SLOT( slotWidChanged() ) );
+      QWhatsThis::add( mTimeZoneList, whatsThis );
 
-      FILE *f;
-      char tempstring[101] = "Unknown";
-      QString sCurrentlySet(i18n("Unknown"));
-      int nCurrentlySet = 0;
-      QStringList list;
-
-      // read the currently set time zone
-    #if defined(USE_SOLARIS)       // MARCO
-        char buf[MAXPATHLEN];
-
-        snprintf(buf, MAXPATHLEN,
-                "/bin/fgrep 'TZ=' %s | /bin/head -n 1 | /bin/cut -b 4-",
-                INITFILE);
-
-        if (f = popen(buf, "r"))
-          {
-           if (fgets(buf, MAXPATHLEN - 1, f) != NULL)
-             {
-               buf[strlen(buf) - 1] = '\0';
-               sCurrentlySet = QString(buf);
-             }
-           pclose(f);
-          }
-    #else
-      if((f = fopen("/etc/timezone", "r")) != NULL) {
-        // get the currently set timezone
-        fgets(tempstring, 100, f);
-        tempstring[strlen(tempstring) - 1] = '\0';
-        sCurrentlySet = QString(tempstring);
-        fclose(f);
-      }
-    #endif // !USE_SOLARIS
-
-      mTimeZoneCombo->insertItem(i18n("[No selection]"));
-
-      // Read all system time zones
-    #if defined(USE_SOLARIS)       // MARCO
-        snprintf(buf, MAXPATHLEN,
-               "/bin/find %s \\( -name src -prune \\) -o -type f -print | /bin/cut -b %d-",
-               ZONEINFODIR, strlen(ZONEINFODIR) + 2);
-
-        if (f = popen(buf, "r"))
-          {
-           while(fgets(buf, MAXPATHLEN - 1, f) != NULL)
-             {
-               buf[strlen(buf) - 1] = '\0';
-               list.append(buf);
-             }
-           pclose(f);
-          }
-
-    #else
-      f = popen("grep -e  ^[^#] /usr/share/zoneinfo/zone.tab | cut -f 3","r");
-      if (!f) return;
-      while(fgets(tempstring, 100, f) != NULL) {
-        tempstring[strlen(tempstring)-1] = '\0';
-        list.append(i18n(tempstring));
-        tzonenames << tempstring;
-      }
-      pclose(f);
-    #endif // !USE_SOLARIS
-      list.sort();
-
-      mTimeZoneCombo->insertStringList(list);
-
-        // find the currently set time zone and select it
-      for ( int i = 0; i < mTimeZoneCombo->count(); ++i )
-        {
-          if (mTimeZoneCombo->text(i) == sCurrentlySet)
-            {
-             nCurrentlySet = i;
-             break;
-            }
-        }
-
-      mTimeZoneCombo->setCurrentItem(nCurrentlySet);
-      QWhatsThis::add( mTimeZoneCombo, whatsThis );
-
       // holiday region selection
       QHBox *holidayRegBox = new QHBox( topFrame );
       topLayout->addMultiCellWidget( holidayRegBox, 1, 1, 0, 1 );
@@ -419,7 +338,7 @@
                                "working hours for this day of the week. "
                                "If this is a work day for you, check "
                                "this box, or the working hours will not be "
-                               "marked with color." ) ); 
+                               "marked with color." ) );
 
         connect( mWorkDays[ index ], SIGNAL( stateChanged( int ) ),
                SLOT( slotWidChanged() ) );
@@ -443,8 +362,7 @@
   protected:
     void usrReadConfig()
     {
-      setCombo( mTimeZoneCombo,
-                i18n( KOPrefs::instance()->mTimeZoneId.utf8() ) );
+      mTimeZoneList->setSelected( KOPrefs::instance()->mTimeZoneId.utf8(), true );
 
       mAlarmTimeCombo->setCurrentItem( KOPrefs::instance()->mAlarmTime );
       for ( int i = 0; i < 7; ++i ) {
@@ -455,14 +373,7 @@
     void usrWriteConfig()
     {
       // Find untranslated selected zone
-      QStringList::Iterator tz;
-      for ( tz = tzonenames.begin(); tz != tzonenames.end(); ++tz )
-        if (mTimeZoneCombo->currentText() == i18n((*tz).utf8()))
-          break;
-      if (tz != tzonenames.end())
-        KOPrefs::instance()->mTimeZoneId = (*tz);
-      else
-        KOPrefs::instance()->mTimeZoneId = mTimeZoneCombo->currentText();
+      KOPrefs::instance()->mTimeZoneId = mTimeZoneList->selection()[0];
 
       KOPrefs::instance()->mHolidays = ( mHolidayCombo->currentItem() == 0 ) ?  // (None)
                                        QString::null :
@@ -477,25 +388,8 @@
       KOPrefs::instance()->writeConfig();
     }
 
-    void setCombo( QComboBox *combo, const QString &text,
-                   const QStringList *tags = 0 )
-    {
-      if (tags) {
-        int i = tags->findIndex(text);
-        if (i > 0) combo->setCurrentItem(i);
-      } else {
-        for(int i=0;i<combo->count();++i) {
-          if (combo->text(i) == text) {
-            combo->setCurrentItem(i);
-            break;
-          }
-        }
-      }
-    }
-
   private:
-    QComboBox    *mTimeZoneCombo;
-    QStringList   tzonenames;
+    KTimezoneWidget *mTimeZoneList;
     QComboBox    *mHolidayCombo;
     QMap<QString,QString> mRegionMap;
     QComboBox    *mAlarmTimeCombo;
@@ -937,7 +831,7 @@
   QPushButton *add = new QPushButton(i18n("New"),topFrame,"new");
   whatsThis = i18n( "Press this button to add a new entry to the "
                     "additional e-mail addresses list. Use the edit "
-                    "box above to edit the new entry." ); 
+                    "box above to edit the new entry." );
   QWhatsThis::add( add, whatsThis );
   topLayout->addWidget(add,5,0);
   QPushButton *del = new QPushButton(i18n("Remove"),topFrame,"remove");


_______________________________________________
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