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

List:       kde-devel
Subject:    Re: Taskbar grouping and binary compatibility
From:       Simon MacMullen <simon () macmullen ! fsnet ! co ! uk>
Date:       2002-02-01 18:27:14
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Replying from home. It's still me.]

Daniel said:
> The patch looks ok at first sight, although I might need some tweaks.

> Anyway
> +    isGrouping == shouldGroup();
> should be 
> +    isGrouping = shouldGroup();

Arrrgh. How embarrassing. Another version is attached. This also works 
properly when the taskbar is vertical (although if the taskbar is full when 
vertical you have problems) and tidies the control panel slightly.

Anyway, do I have to worry about binary compatibility, or what?

Cheers,

Simon
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8Wt4NL1TpxBN32NgRAqa6AKCAJKGSsJhLcM2h2yjvXBCIza7p8gCdGp+T
RqsRLIT1j348RlGduxO1sr4=
=KxYq
-----END PGP SIGNATURE-----

["groupwhenfullpatch.txt" (text/x-diff)]

? groupwhenfullpatch.txt
Index: kcontrol/taskbar/kcmtaskbar.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/taskbar/kcmtaskbar.cpp,v
retrieving revision 1.26
diff -u -3 -p -u -p -r1.26 kcmtaskbar.cpp
--- kcontrol/taskbar/kcmtaskbar.cpp	2002/01/25 09:49:57	1.26
+++ kcontrol/taskbar/kcmtaskbar.cpp	2002/02/01 18:12:39
@@ -80,6 +80,45 @@ QString TaskbarConfig::buttonAction( int
    return actionList()[action];
 }
 
+// These are the strings that are actually stored in the config file.
+const QStringList& TaskbarConfig::groupModeList()
+{
+    static QStringList list(
+            QStringList() << I18N_NOOP("Never") << I18N_NOOP("When Taskbar Full")
+            << I18N_NOOP("Always"));
+    return list;
+}
+
+// Get a translated version of the above string list.
+QStringList TaskbarConfig::i18nGroupModeList()
+{
+   QStringList i18nList;
+   for( QStringList::ConstIterator it = groupModeList().begin(); it != \
groupModeList().end(); ++it ) { +      i18nList << i18n((*it).latin1());
+   }
+   return i18nList;
+}
+
+// Translate from config entry name to enumeration
+enum TaskbarConfig::GroupMode TaskbarConfig::groupMode(const QString& groupModeName \
) +{
+   int index = groupModeList().findIndex( groupModeName );
+   if( index != -1 ) return static_cast<GroupMode>(index);
+
+   // Translate old entries
+   if( groupModeName == "true" ) return GroupAlways;
+   if( groupModeName == "false" ) return GroupNever;
+
+   // Otherwise return the default.
+   return GroupWhenFull;
+}
+
+// Translate from enum (or integer) to config entry name.
+QString TaskbarConfig::groupMode( int groupModeNum )
+{
+   return groupModeList()[groupModeNum];
+}
+
 TaskbarConfig::TaskbarConfig( QWidget *parent, const char* name, const QStringList & \
)  : KCModule (TaskBarFactory::instance(), parent, name)
 {
@@ -90,7 +129,6 @@ TaskbarConfig::TaskbarConfig( QWidget *p
     vbox->addWidget(ui);
     connect(ui->showAllCheck, SIGNAL(clicked()), SLOT(configChanged()));
     connect(ui->showListBtnCheck, SIGNAL(clicked()), SLOT(configChanged()));
-    connect(ui->groupCheck, SIGNAL(clicked()), SLOT(configChanged()));
     connect(ui->sortCheck, SIGNAL(clicked()), SLOT(configChanged()));
     connect(ui->iconCheck, SIGNAL(clicked()), SLOT(configChanged()));
 
@@ -98,11 +136,13 @@ TaskbarConfig::TaskbarConfig( QWidget *p
     ui->leftButtonComboBox->insertStringList( list );
     ui->middleButtonComboBox->insertStringList( list );
     ui->rightButtonComboBox->insertStringList( list );
+    ui->groupComboBox->insertStringList( i18nGroupModeList() );
+
     connect(ui->leftButtonComboBox, SIGNAL(activated(int)), SLOT(configChanged()));
     connect(ui->middleButtonComboBox, SIGNAL(activated(int)), \
                SLOT(configChanged()));
     connect(ui->rightButtonComboBox, SIGNAL(activated(int)), SLOT(configChanged()));
-
-    connect(ui->groupCheck, SIGNAL(clicked()), SLOT(slotUpdateComboBox()));
+    connect(ui->groupComboBox, SIGNAL(clicked()), SLOT(configChanged()));
+    connect(ui->groupComboBox, SIGNAL(clicked()), SLOT(slotUpdateComboBox()));
 
     load();
 }
@@ -120,7 +160,7 @@ void TaskbarConfig::slotUpdateComboBox()
 {
     // If grouping is enabled, call "Activate, Raise or Iconify something else,
     // though the config key used is the same.
-    if( ui->groupCheck->isChecked() ) {
+    if( ui->groupComboBox->currentItem() != GroupNever ) {
 	ui->leftButtonComboBox->changeItem(i18n("Cycle Through \
Windows"),ActivateRaiseOrIconify);  ui->middleButtonComboBox->changeItem(i18n("Cycle \
Through Windows"),ActivateRaiseOrIconify);  \
ui->rightButtonComboBox->changeItem(i18n("Cycle Through \
Windows"),ActivateRaiseOrIconify); @@ -140,12 +180,12 @@ void TaskbarConfig::load()
 
         ui->showAllCheck->setChecked(c->readBoolEntry("ShowAllWindows", true));
         ui->showListBtnCheck->setChecked(c->readBoolEntry("ShowWindowListBtn", \
                true));
-        ui->groupCheck->setChecked(c->readBoolEntry("GroupTasks", true));
 	ui->sortCheck->setChecked(c->readBoolEntry("SortByDesktop", true));
 	ui->iconCheck->setChecked(c->readBoolEntry("ShowIcon", true));
 	ui->leftButtonComboBox->setCurrentItem(buttonAction(LeftButton, \
c->readEntry("LeftButtonAction")));  \
ui->middleButtonComboBox->setCurrentItem(buttonAction(MidButton, \
c->readEntry("MiddleButtonAction")));  \
ui->rightButtonComboBox->setCurrentItem(buttonAction(RightButton, \
c->readEntry("RightButtonAction"))); +        \
ui->groupComboBox->setCurrentItem(groupMode(c->readEntry("GroupTasks")));  }
 
     delete c;
@@ -161,13 +201,13 @@ void TaskbarConfig::save()
 
         c->writeEntry("ShowAllWindows", ui->showAllCheck->isChecked());
         c->writeEntry("ShowWindowListBtn", ui->showListBtnCheck->isChecked());
-        c->writeEntry("GroupTasks", ui->groupCheck->isChecked());
         c->writeEntry("SortByDesktop", ui->sortCheck->isChecked());
         c->writeEntry("ShowIcon", ui->iconCheck->isChecked());
         c->writeEntry("LeftButtonAction", \
                buttonAction(ui->leftButtonComboBox->currentItem()));
         c->writeEntry("MiddleButtonAction", \
                buttonAction(ui->middleButtonComboBox->currentItem()));
         c->writeEntry("RightButtonAction", \
                buttonAction(ui->rightButtonComboBox->currentItem()));
-        c->sync();
+        c->writeEntry("GroupTasks", groupMode(ui->groupComboBox->currentItem()));
+	c->sync();
     }
 
     delete c;
@@ -185,11 +225,11 @@ void TaskbarConfig::defaults()
 {
     ui->showAllCheck->setChecked(true);
     ui->showListBtnCheck->setChecked(true);
-    ui->groupCheck->setChecked(true);
     ui->sortCheck->setChecked(true);
     ui->leftButtonComboBox->setCurrentItem( buttonAction( LeftButton ) );
     ui->middleButtonComboBox->setCurrentItem( buttonAction( MidButton ) );
     ui->rightButtonComboBox->setCurrentItem( buttonAction( RightButton ) );
+    ui->groupComboBox->setCurrentItem( groupMode() );
     emit changed(true);
     slotUpdateComboBox();
 }
Index: kcontrol/taskbar/kcmtaskbar.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/taskbar/kcmtaskbar.h,v
retrieving revision 1.11
diff -u -3 -p -u -p -r1.11 kcmtaskbar.h
--- kcontrol/taskbar/kcmtaskbar.h	2002/01/02 03:23:55	1.11
+++ kcontrol/taskbar/kcmtaskbar.h	2002/02/01 18:12:39
@@ -53,10 +53,19 @@ private:
         Raise,
         Lower,
         Iconify };
+    enum GroupMode {
+        GroupNever = 0,
+        GroupWhenFull,
+        GroupAlways };
+
     static Action buttonAction( ButtonState button, const QString& actionName = \
QString::null );  static QString buttonAction( int action );
     static const QStringList& actionList();
     static QStringList i18nActionList();
+    static GroupMode groupMode( const QString& groupModeName = QString::null );
+    static QString groupMode( int groupModeNum );
+    static const QStringList& groupModeList();
+    static QStringList i18nGroupModeList();
     TaskbarConfigUI *ui;
 };
 
Index: kcontrol/taskbar/kcmtaskbarui.ui
===================================================================
RCS file: /home/kde/kdebase/kcontrol/taskbar/kcmtaskbarui.ui,v
retrieving revision 1.7
diff -u -3 -p -u -p -r1.7 kcmtaskbarui.ui
--- kcontrol/taskbar/kcmtaskbarui.ui	2002/01/08 11:07:25	1.7
+++ kcontrol/taskbar/kcmtaskbarui.ui	2002/02/01 18:12:39
@@ -78,20 +78,6 @@
                 </widget>
                 <widget class="QCheckBox">
                     <property name="name">
-                        <cstring>groupCheck</cstring>
-                    </property>
-                    <property name="text">
-                        <string>&amp;Group similar tasks</string>
-                    </property>
-                    <property name="checked">
-                        <bool>true</bool>
-                    </property>
-                    <property name="whatsThis" stdset="0">
-                        <string>Check this option if you want the taskbar to hold \
all running instances of one application in one taskbutton. Clicking on the button \
for some seconds will unfold a menu which shows all instances of the application. \
This is especially useful with the "&lt;strong&gt;Show all windows&lt;/strong&gt;" \
                option.</string>
-                    </property>
-                </widget>
-                <widget class="QCheckBox">
-                    <property name="name">
                         <cstring>sortCheck</cstring>
                     </property>
                     <property name="text">
@@ -118,6 +104,30 @@
                         <string>Check this option if you want to display the \
applications icon in the taskbar</string>  </property>
                 </widget>
+		<hbox>
+	        <property name="margin">
+		        <number>2</number>
+	        </property>
+	        <property name="spacing">
+		        <number>2</number>
+	        </property>
+		<widget class="QLabel">
+		<property name="name">
+			<cstring>groupTasksLabel</cstring>
+		</property>
+		<property name="text">
+			<string>Group similar tasks</string>
+		</property>
+		</widget>
+                <widget class="QComboBox">
+                    <property name="name">
+                        <cstring>groupComboBox</cstring>
+                    </property>
+		    <property name="whatsThis" stdset="0">
+		        <string>Check this option if you want the taskbar to hold all running \
instances of one application in one taskbutton. Clicking on the button for some \
seconds will unfold a menu which shows all instances of the application. This is \
especially useful with the "&lt;strong&gt;Show all windows&lt;/strong&gt;" \
option.</string> +		    </property>
+                </widget>
+		</hbox>
             </vbox>
         </widget>
         <widget class="QGroupBox">
@@ -200,7 +210,7 @@
 <tabstops>
     <tabstop>showAllCheck</tabstop>
     <tabstop>showListBtnCheck</tabstop>
-    <tabstop>groupCheck</tabstop>
+    <tabstop>groupComboBox</tabstop>
     <tabstop>sortCheck</tabstop>
     <tabstop>iconCheck</tabstop>
     <tabstop>leftButtonComboBox</tabstop>
Index: kicker/taskbar/taskbar.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/taskbar/taskbar.cpp,v
retrieving revision 1.37
diff -u -3 -p -u -p -r1.37 taskbar.cpp
--- kicker/taskbar/taskbar.cpp	2002/01/02 03:47:35	1.37
+++ kicker/taskbar/taskbar.cpp	2002/02/01 18:12:39
@@ -77,6 +77,8 @@ TaskBar::TaskBar( QWidget *parent, const
     connect( taskManager(), SIGNAL( desktopChanged( int ) ), SLOT( desktopChanged( \
                int ) ) );
     connect( taskManager(), SIGNAL( windowDesktopChanged( WId ) ), SLOT( \
windowDesktopChanged( WId ) ) );  
+    isGrouping = shouldGroup();
+
     // register existant tasks
     TaskList tasks = taskManager()->tasks();
     for (Task* t = tasks.first(); t!=0; t = tasks.next())
@@ -136,6 +138,29 @@ enum TaskBar::Action TaskBar::buttonActi
    }
 }
 
+// These are the strings that are actually stored in the config file.
+const QStringList& TaskBar::groupModeList()
+{
+    static QStringList list(
+            QStringList() << I18N_NOOP("Never") << I18N_NOOP("When Taskbar Full")
+            << I18N_NOOP("Always"));
+    return list;
+}
+
+// Translate from config entry name to enumeration
+enum TaskBar::GroupMode TaskBar::groupMode(const QString& groupModeName )
+{
+   int index = groupModeList().findIndex( groupModeName );
+   if( index != -1 ) return static_cast<GroupMode>(index);
+
+   // Translate old entries
+   if( groupModeName == "true" ) return GroupAlways;
+   if( groupModeName == "false" ) return GroupNever;
+
+   // Otherwise return the default.
+   return GroupWhenFull;
+}
+
 void TaskBar::configure()
 {
    // read settings
@@ -143,7 +168,7 @@ void TaskBar::configure()
     c.setGroup( "General" );
 
     showAllWindows = c.readBoolEntry( "ShowAllWindows", true );
-    groupTasks = c.readBoolEntry( "GroupTasks", true );
+    currentGroupMode = groupMode( c.readEntry( "GroupTasks" ) );
     sortByDesktop = c.readBoolEntry( "SortByDesktop", true );
     showIcon = c.readBoolEntry( "ShowIcon", true );
     maxButtonWidth = c.readNumEntry( "MaximumButtonWidth", BUTTON_MAX_WIDTH );
@@ -189,7 +214,7 @@ void TaskBar::add( Task* task )
     if ( !task ) return;
 
     // try to group
-    if ( groupTasks ) {
+    if ( isGrouping ) {
 	for ( TaskContainer *c = containers.first(); c; c = containers.next() )
 	    if ( idMatch( task->className().lower(), c->id().lower() ) ) {
 		c->add( task );
@@ -215,7 +240,7 @@ void TaskBar::add( Startup* startup )
     if ( !startup ) return;
 
     // try to group
-    if ( groupTasks ) {
+    if ( isGrouping ) {
 	for ( TaskContainer *c = containers.first(); c; c = containers.next() )
 	    if ( idMatch( startup->bin().lower(), c->id().lower() ) ) {
 		c->add( startup );
@@ -254,7 +279,8 @@ void TaskBar::remove( Task *task )
 	delete c;
 	emit containerCountChanged();
     }
-    reLayout();
+    if ( !blocklayout )
+	reLayout();
 }
 
 void TaskBar::remove( Startup *startup )
@@ -278,8 +304,8 @@ void TaskBar::remove( Startup *startup )
 	emit containerCountChanged();
     }
 
-    if (found)
-      reLayout();
+    if (found && !blocklayout )
+	reLayout();
 }
 
 void TaskBar::desktopChanged( int desktop )
@@ -321,6 +347,11 @@ void TaskBar::reLayout()
     }
     if ( list.count() < 1 ) return;
 
+    if ( isGrouping != shouldGroup() ) {
+        reGroup();
+	return;
+    }
+
     // sort container list by desktop
     if ( sortByDesktop ) {
 	TaskContainerList sorted;
@@ -486,4 +517,60 @@ int TaskBar::containerCount() const
 	}
     }
     return i;
+}
+
+int TaskBar::taskCount() const
+{
+    int i = 0;
+    TaskContainerListIterator it(containers);
+    for ( ; it.current(); ++it ) {
+	if ( showAllWindows || (*it)->onCurrentDesktop() ) {
+	    i += (*it)->filteredTaskCount();
+	}
+    }
+    return i;
+}
+
+int TaskBar::maximumButtonsWithoutShrinking() const
+{
+    int rows = contentsRect().height() / BUTTON_MIN_HEIGHT;
+    if ( rows < 1 ) rows = 1;
+
+    if ( orientation() == Horizontal ) {
+	// They squash a bit before they pop, hence the 2
+	return rows * (contentsRect().width() / maxButtonWidth) + 2;
+    } else {
+        // Overlap slightly and ugly arrows appear, hence -1
+        return rows - 1;
+    }
+}
+
+bool TaskBar::shouldGroup() const
+{
+    return currentGroupMode == GroupAlways ||
+        ( currentGroupMode == GroupWhenFull &&
+          taskCount() > maximumButtonsWithoutShrinking() );
+}
+
+void TaskBar::reGroup()
+{
+    isGrouping = shouldGroup();
+    blocklayout = TRUE;
+
+    TaskList tasks = taskManager()->tasks();
+    for (Task* t = tasks.first(); t!=0; t = tasks.next())
+	remove( t );
+
+    StartupList startups = taskManager()->startups();
+    for (Startup* s = startups.first(); s!=0; s = startups.next())
+	remove( s );
+
+    for (Task* t = tasks.first(); t!=0; t = tasks.next())
+	add( t );
+
+    for (Startup* s = startups.first(); s!=0; s = startups.next())
+	add( s );
+
+    blocklayout = FALSE;
+    reLayout();
 }
Index: kicker/taskbar/taskbar.h
===================================================================
RCS file: /home/kde/kdebase/kicker/taskbar/taskbar.h,v
retrieving revision 1.19
diff -u -3 -p -u -p -r1.19 taskbar.h
--- kicker/taskbar/taskbar.h	2002/01/02 03:26:34	1.19
+++ kicker/taskbar/taskbar.h	2002/02/01 18:12:39
@@ -48,6 +48,10 @@ public:
         Raise,
         Lower,
         Iconify };
+    enum GroupMode {
+        GroupNever = 0,
+        GroupWhenFull,
+        GroupAlways };
 
     TaskBar( QWidget *parent = 0, const char *name = 0 );
     ~TaskBar();
@@ -61,6 +65,7 @@ public:
 
     void configure();
     int containerCount() const;
+    int taskCount() const;
 
 signals:
     void containerCountChanged();
@@ -88,17 +93,23 @@ protected:
 
 private:
     static const QStringList& actionList();
+    static const QStringList& groupModeList();
     static Action buttonAction( ButtonState button, const QString& actionName = \
QString::null ); +    static GroupMode groupMode( const QString& groupModeName = \
QString::null );  static 			TaskManager* manager;
     bool 			blocklayout;
     bool			showAllWindows;
-    bool			groupTasks;
+    int 			currentGroupMode;
     bool 			sortByDesktop;
     bool			showIcon;
     int				maxButtonWidth;
     ArrowType 			arrowType;
     TaskContainerList		containers;
     PixmapList			*frames;
+    int                         maximumButtonsWithoutShrinking() const;
+    bool                        shouldGroup() const;
+    bool                        isGrouping;
+    void                        reGroup();
 };
 
 #endif
Index: kicker/taskbar/taskcontainer.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/taskbar/taskcontainer.cpp,v
retrieving revision 1.59
diff -u -3 -p -u -p -r1.59 taskcontainer.cpp
--- kicker/taskbar/taskcontainer.cpp	2002/01/12 16:16:39	1.59
+++ kicker/taskbar/taskcontainer.cpp	2002/02/01 18:12:39
@@ -750,6 +750,10 @@ void TaskContainer::updateFilteredTaskLi
     }
 }
 
+int TaskContainer::filteredTaskCount() const {
+    return ftasks.count();
+}
+
 void TaskContainer::desktopChanged( int )
 {
     updateFilteredTaskList();
Index: kicker/taskbar/taskcontainer.h
===================================================================
RCS file: /home/kde/kdebase/kicker/taskbar/taskcontainer.h,v
retrieving revision 1.23
diff -u -3 -p -u -p -r1.23 taskcontainer.h
--- kicker/taskbar/taskcontainer.h	2002/01/02 03:26:34	1.23
+++ kicker/taskbar/taskcontainer.h	2002/02/01 18:12:39
@@ -70,6 +70,8 @@ public:
     bool isEmpty();
     bool onCurrentDesktop();
 
+    int filteredTaskCount() const;
+
     QString id();
     int desktop();
     QString name();


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

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

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