[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Devel] kschoolmenu



On Fri, Jul 25, 2003 at 03:05:02AM +0200, Tim Vandermeersch wrote:
> Petter Reinholdtsen wrote:
> >[Tim Vandermeersch]
> >>At debcamp/debconf one of the skolelinux developers asked me if I
> >>could finish the kschoolmenu program, wich I did.
> >Good to see that you are active developing. :)
> >But isn't it better if you commit your changes directly into the
> >Skolelinux CVS, or send some patches instead of a new version of the
> >source?
> >>I attached the new version to this email, If something needs to be
> >>changed, let me know.
> >Please do not send large binary files as attachments to mailing lists.
> I won't attach any large binary files anymore...
> 
> Klaus Ada Johnstad asked if this version works with kde 3.1. The first 
> version I posted to the mailing list didn't work with kde 3.1, that's 
> why I post this version wich works with kde 3.1.
> The reason why I post the changes to the mailinglist is that I want to 
> know what you think of it before I actually commit the changes into the 
> skolelinux CVS.

I the future, please commit it right away. Now the bruden is on someone
else to check if this works and so on. to fix that I had to create a
branch (taged with the name "Tim_Vandermeersch"). So now we have a
separate branch with your changes, in adition to the "HEAD" branch. 

Please get write access to the cvs on developer.skolelinux.no (or more
correctly: cvs.skolelinux.no)

please look at http://developer.skolelinux.no/cvsusage.html.en

> Is there an irc channel for skolelinux?

I believe Knut Answered this, but, yes: 
#skolelinux on irc.ifi.uio.no (among others). 

> 
> Tim
> 

> diff -ru skolelinux-orig/src/kschoolmenu/Xsession.d/25kschoolmenu-kdedirs skolelinux/src/kschoolmenu/Xsession.d/25kschoolmenu-kdedirs
> --- skolelinux-orig/src/kschoolmenu/Xsession.d/25kschoolmenu-kdedirs	2003-04-22 03:01:59.000000000 +0200
> +++ skolelinux/src/kschoolmenu/Xsession.d/25kschoolmenu-kdedirs	2003-07-24 16:18:57.000000000 +0200
> @@ -1,5 +1,3 @@
> -#!/bin/bash
> -
>  KDEDIRS_ORG="$KDEDIRS"
>  KDEDIRS=""
>  
> diff -ru skolelinux-orig/src/kschoolmenu/configure skolelinux/src/kschoolmenu/configure
> --- skolelinux-orig/src/kschoolmenu/configure	2003-04-22 08:42:19.000000000 +0200
> +++ skolelinux/src/kschoolmenu/configure	2003-07-24 21:33:50.000000000 +0200
> @@ -4100,7 +4100,7 @@
>    
>  
>  
> -if test -z "2"; then
> +if test -e "/usr/lib/kde3"; then
>    kde_qtver=3
>    kde_qtsubver=1
>  else
> @@ -6663,7 +6663,7 @@
>  for dir in $kde_qt_dirs; do
>     qt_incdirs="$qt_incdirs $dir/include $dir"
>  done
> -qt_incdirs="$QTINC $qt_incdirs /usr/local/qt/include /usr/include/qt /usr/include /usr/X11R6/include/X11/qt /usr/X11R6/include/qt /usr/X11R6/include/qt2 $x_includes"
> +qt_incdirs="$QTINC $qt_incdirs /usr/local/qt/include /usr/include/qt /usr/include/qt3 /usr/include /usr/X11R6/include/X11/qt /usr/X11R6/include/qt /usr/X11R6/include/qt2 $x_includes"
>  if test ! "$ac_qt_includes" = "NO"; then
>     qt_incdirs="$ac_qt_includes $qt_incdirs"
>  fi
> diff -ru skolelinux-orig/src/kschoolmenu/debian/rules skolelinux/src/kschoolmenu/debian/rules
> --- skolelinux-orig/src/kschoolmenu/debian/rules	2003-04-24 04:38:38.000000000 +0200
> +++ skolelinux/src/kschoolmenu/debian/rules	2003-07-17 17:18:17.000000000 +0200
> @@ -33,6 +33,7 @@
>  	dh_testdir
>  
>  	# Add here commands to compile the package.
> +	moc kschoolmenu/kschoolmenu.h -o kschoolmenu/kschoolmenu.moc
>  	$(MAKE)
>  	#/usr/bin/docbook-to-man debian/kschoolmenu.sgml > kschoolmenu.1
>  
> @@ -45,6 +46,7 @@
>  
>  	# Add here commands to clean up after the build process.
>  	-$(MAKE) distclean
> +	-rm kschoolmenu/kschoolmenu.moc
>  	-test -r /usr/share/misc/config.sub && \
>  	  cp -f /usr/share/misc/config.sub config.sub
>  	-test -r /usr/share/misc/config.guess && \
> diff -ru skolelinux-orig/src/kschoolmenu/kschoolmenu/kschoolmenu.cpp skolelinux/src/kschoolmenu/kschoolmenu/kschoolmenu.cpp
> --- skolelinux-orig/src/kschoolmenu/kschoolmenu/kschoolmenu.cpp	2003-04-29 21:29:49.000000000 +0200
> +++ skolelinux/src/kschoolmenu/kschoolmenu/kschoolmenu.cpp	2003-07-24 20:33:53.000000000 +0200
> @@ -41,7 +41,6 @@
>  
>  #include <iostream>
>  
> -
>  MenuItem::MenuItem(const QPixmap& icon, const QString& name, const QString& path)
>    : icon(icon),
>      name(name),
> @@ -56,7 +55,6 @@
>      if(file.open(IO_ReadOnly))
>      {
>        desktopFile = QTextStream(&file).read();
> -
>        file.close();
>      }
>    }
> @@ -70,7 +68,7 @@
>  
>  void MenuItem::Show()
>  {
> -  cout << "Debug: menuitem::Show: " << name << "\n";
> +  hidden = false;
>  }
>  
>  void MenuItem::Hide()
> @@ -87,34 +85,23 @@
>  
>  static void read_desktop_files(MenuItem* item, const QString& path)
>  {
> -
>    if(item->path.contains(".desktop"))
> -  {
> -    QFile file(path + item->path.right(item->path.length() - item->path.findRev('/')));
> -
> -    if(file.open(IO_ReadOnly))
> -    {
> -      QTextStream stream(&file);
> -      file.close();
> +  { 
> +    KDesktopFile desktopFile(path + item->path.right(item->path.length() - item->path.findRev('/')));
> +    // check if we should really hide the item
> +    if(desktopFile.readBoolEntry("NoDisplay") || desktopFile.readBoolEntry("Hidden"))
>        item->Hide();
> -      cout << "Debug: read_desktop_files: hide: " << file.name() << "\n" ;
> -      
> -    }
>    }
>    else
>    {
> -    QFile file(path + '/' + item->path.right(item->path.length() - item->path.findRev('/')) + "/.directory");
> -
> -    if(file.open(IO_ReadOnly))
> -    {
> -      QTextStream stream(&file);
> -      file.close();
> +    KDesktopFile desktopFile(path + item->path.right(item->path.length() - item->path.findRev('/')) + "/.directory");
> +    // check if we should really hide the item
> +    if(desktopFile.readBoolEntry("NoDisplay") || desktopFile.readBoolEntry("Hidden"))
>        item->Hide();
> -      cout << "Debug: read_desktop_files: hide: " << file.name() << "\n" ;
> -    }
> -
> +    
> +    // call read_desktop_files() for all files and subdirectories in path
>      for(uint i = 0; i < item->children.size(); ++i) 
> -      read_desktop_files(item->children[i], path + '/' + item->path.right(item->path.length() - item->path.findRev('/'))); 
> +      read_desktop_files(item->children[i], path + item->path.right(item->path.length() - item->path.findRev('/'))); 
>    }
>  }
>  
> @@ -135,14 +122,19 @@
>      if(info.isDir())
>      {
>        KDesktopFile desktopFile(info.filePath() + "/.directory");
> +      QString itemName;
>  
>        if(desktopFile.readBoolEntry("NoDisplay") || desktopFile.readBoolEntry("Hidden"))
>          continue;
>  
> +      itemName = desktopFile.readName();
> +      if (!itemName)
> +        itemName = dir[i];
> +      
>        MenuItem* item = new MenuItem(
>          KGlobal::iconLoader()->loadIcon(desktopFile.readIcon(), KIcon::Desktop, KIcon::SizeSmall),
> -        desktopFile.readName(),
> -        info.filePath().right(info.filePath().length() - path.length() - 1));
> +        itemName,
> +        info.filePath());
>  
>        QFile file(info.filePath() + "/.directory");
>  
> @@ -160,14 +152,18 @@
>      else
>      {
>        KDesktopFile desktopFile(info.filePath());
> +      QString itemName;
>  
>        if(desktopFile.readBoolEntry("NoDisplay") || desktopFile.readBoolEntry("Hidden"))
>          continue;
>  
> +      itemName = desktopFile.readName();
> +      if (!itemName)
> +        itemName = dir[i];
> + 
>        MenuItem* item = new MenuItem(
>          KGlobal::iconLoader()->loadIcon(desktopFile.readIcon(), KIcon::Desktop, KIcon::SizeSmall),
> -        desktopFile.readName(),
> -        info.filePath());
> +        itemName, info.filePath());
>  
>        push_back(parent.children, item);
>      }
> @@ -243,21 +239,27 @@
>  }
>  
>  template<class type>
> -static void add_children(const MenuItem& parentItem, type* parentWidget)
> +static void add_children(const MenuItem& parentItem, type* parentWidget, const QString &open, const QString &select)
>  {
>    for(uint i = 0; i < parentItem.children.size(); ++i)
>    {
>      if (! parentItem.children[i]->Hidden())
>      {
> -			QListViewItem* item = new QListViewItem(parentWidget, parentItem.children[i]->name, parentItem.children[i]->path);
> +      QListViewItem* item = new QListViewItem(parentWidget, parentItem.children[i]->name, parentItem.children[i]->path);
>  
> -			item->setPixmap(0, parentItem.children[i]->icon);
> +      item->setPixmap(0, parentItem.children[i]->icon);
>  
> -			if(!parentItem.children[i]->path.contains(".desktop"))
> -				item->setExpandable(true);
> +      if(!parentItem.children[i]->path.contains(".desktop"))
> +      {
> +        item->setExpandable(true);
> +	if (open.contains(parentItem.children[i]->path))
> +	  item->setOpen(true);
> +      }
> +      if (select == parentItem.children[i]->path)
> +        item->setSelected(true);
>  
> -			add_children(*parentItem.children[i], item);
> -		}
> +      add_children(*parentItem.children[i], item, open, select);
> +    }
>    }
>  }
>  
> @@ -277,16 +279,17 @@
>    dir.setSorting(QDir::Name);
>    dir.setMatchAllDirs(true);
>  
> +  // for every directory in /var/lib/kschoolmenu/
>    for(uint i = 0; i < dir.count(); ++i)
>    {
>      if(dir[i] == "." || dir[i] == "..")
>        continue;
>  
> -    
>      MenuItem* item = new MenuItem(QPixmap(), dir[i], QString("/var/lib/kschoolmenu/") + dir[i] + "/share/applnk");
>  
> +    // read the files for the QListViews
>      read_dir ("/usr/share/applnk", *item);
> -
> +    // hide the files for the listCurrentMenu QListView
>      read_desktop_files(item, "/var/lib/kschoolmenu/" + dir[i] + "/share") ;
>  
>      push_back(customMenus, item);
> @@ -299,7 +302,7 @@
>    listCurrentMenu->header()->hide();
>    listCurrentMenu->setRootIsDecorated(true);
>  
> -  add_children(availableItems, listAvailableItems);
> +  add_children(availableItems, listAvailableItems, NULL, NULL);
>  
>    comboCustomMenusActivated(comboCustomMenus->currentItem());
>  }
> @@ -357,43 +360,45 @@
>  {
>    if(item->path.contains(".desktop"))
>    {
> -    if (!item->Hidden())
> -      return;
> -
> -    item->desktopFile = "[Desktop Entry]\nHidden=true\nName=empty";
> -
>      QFile file(path + item->path.right(item->path.length() - item->path.findRev('/')));
> -
> -    if(file.open(IO_WriteOnly))
> +    if (item->Hidden())
>      {
> -      QTextStream stream(&file);
> -
> -      stream << item->desktopFile;
> +      item->desktopFile = "[Desktop Entry]\nHidden=true\nName=empty";
>  
> -      file.close();
> +      if(file.open(IO_WriteOnly))
> +      {
> +        QTextStream stream(&file);
> +        stream << item->desktopFile;
> +        file.close();
> +      }
>      }
> +    else
> +      file.remove(); 
>    }
>    else
>    {
> +    QFile file(path + item->path.right(item->path.length() - item->path.findRev('/')) + "/.directory");
>      if (find_hidden(item))
> -      QDir().mkdir(path + "/" + item->path);
> +      QDir().mkdir(path + item->path.right(item->path.length() - item->path.findRev('/')));
>      if(item->Hidden())
>      {
> -      QFile file(path + "/" + item->path + "/.directory");
>        item->desktopFile = "[Desktop Entry]\nHidden=true\nName=empty";
>  
>        if(file.open(IO_WriteOnly))
>        {
>          QTextStream stream(&file);
> -
>          stream << item->desktopFile;
> -
>          file.close();
>        }
>      }
> +    else
> +      file.remove(); 
>  
> -    for(uint i = 0; i < item->children.size(); ++i) 
> -      write_desktop_files(item->children[i], path + "/" + item->path);
> +    for(uint i = 0; i < item->children.size(); ++i)
> +      if (path == "")
> +        write_desktop_files(item->children[i], path + item->path);
> +      else
> +        write_desktop_files(item->children[i], path + '/' + item->path.right(item->path.length() - item->path.findRev('/') - 1));
>    }
>  }
>  
> @@ -519,14 +524,29 @@
>    emit changed(true);
>  }
>  
> -MenuItem* find_item(MenuItem* menu, const QString& path)
> +MenuItem* find_item(MenuItem* menu, const QString& path, const QString& name)
>  {
> -  if(menu->name == path)
> -    return menu;
> +  if(menu->path.left(menu->path.findRev('/')) == path)
> +  {
> +    if(menu->path.contains(".desktop"))
> +    { 
> +      KDesktopFile desktopFile(menu->path);
> +
> +      if(desktopFile.readName() == name)
> +        return menu;
> +    }
> +    else
> +    {
> +      KDesktopFile desktopFile(menu->path + "/.directory");
> +
> +      if(desktopFile.readName() == name || menu->path.right(menu->path.length() - menu->path.findRev('/') - 1) == name)
> +        return menu;
> +    } 
> +  }
>  
>    for(uint i = 0; i < menu->children.size(); ++i)
>    {
> -    MenuItem* ret = find_item(menu->children[i], path);
> +    MenuItem* ret = find_item(menu->children[i], path, name);
>  
>      if(ret)
>        return ret;
> @@ -549,30 +569,29 @@
>        break;
>      }
>  
> -  QListViewItem* newItemParent = listCurrentMenu->currentItem();
> -
> -  if(newItemParent && !newItemParent->isExpandable())
> -    newItemParent = newItemParent->parent();
> -
> -  QListViewItem* newItem;
> -  
> -  if(!newItemParent)
> +  MenuItem *tmpItem = find_item(menu, item->text(1).left(item->text(1).findRev('/')), item->text(0));
> +  QString open = item->text(1);
> +  QString select = open;
> +  if (tmpItem->Hidden())
>    {
> -    newItem = new QListViewItem(listCurrentMenu, item->text(0), item->text(1));
> -    push_back(menu->children, new MenuItem(*item->pixmap(0), item->text(0), item->text(1)));
> +    tmpItem->Show();
> +    listCurrentMenu->clear();
> +    add_children(*menu, listCurrentMenu, open, select);
>    }
> -  else
> -  {
> -    newItem = new QListViewItem(newItemParent, item->text(0), item->text(1));
>  
> -    if(!newItemParent->isOpen())
> -      newItemParent->setOpen(true);
> -
> -    push_back(find_item(menu, newItemParent->text(1))->children, new MenuItem(*item->pixmap(0), item->text(0), item->text(1)));
> +  while (item->parent())
> +  {
> +    item = item->parent(); 
> +    open += item->text(1);
> +    MenuItem *tmpItem = find_item(menu, item->text(1).left(item->text(1).findRev('/')), item->text(0));
> +    if (tmpItem->Hidden())
> +    {
> +      tmpItem->Show();
> +      listCurrentMenu->clear();
> +      add_children(*menu, listCurrentMenu, open, select);
> +    }
>    }
> -
> -  newItem->setPixmap(0, *item->pixmap(0));
> -
> +  
>    emit changed(true);
>  }
>  
> @@ -591,14 +610,19 @@
>        break;
>      }
>  
> -
>    // search to find top List-handle 
>    QListViewItem* topFound = toHide ;
> -  while (topFound->parent()) topFound = topFound->parent() ;
> -
> +  QString path = "/usr/share/applnk"; 
> + 
> +  while (topFound->parent()) 
> +    topFound = topFound->parent() ;
> +  
> +  if (toHide->parent())
> +    path = toHide->parent()->text(1);
> +  
>    while (topFound != toHide)
>    {
> -    item = find_item (item, topFound->text(0));
> +    item = find_item (item, path, toHide->text(0));
>      QListViewItem* listTraverse = toHide ; 
>      while (listTraverse->parent() != topFound)
>        listTraverse = listTraverse->parent();
> @@ -607,9 +631,8 @@
>  
>    if (topFound == toHide)
>    {
> -    item = find_item (item, topFound->text(0));
> +    item = find_item (item, path, toHide->text(0));
>      item->Hide() ; 
> -  
>      delete listCurrentMenu->currentItem();
>  
>      if(listCurrentMenu->currentItem())
> @@ -630,10 +653,6 @@
>    }
>  
>    // if(!listAvailableItems->currentItem()->isExpandable() && buttonRemove->isEnabled())
> -
> -/*
> -  // Adding elements to the menu is disabled for now (only removal)
> -  
>    if(buttonRemove->isEnabled())
>    {
>      buttonRight->setEnabled(true);
> @@ -642,7 +661,6 @@
>    {
>      buttonRight->setEnabled(false);
>    }
> -*/
>  }
>  
>  void KSchoolmenu::listCurrentMenuSelectionChanged()
> @@ -676,7 +694,7 @@
>      {
>        if(customMenus[i]->name == comboCustomMenus->currentText())
>        {
> -        add_children(*customMenus[i], listCurrentMenu);
> +        add_children(*customMenus[i], listCurrentMenu, NULL, NULL);
>  
>          break;
>        }


-- 
Finn-Arne Johansen 
faj@xxxxxx
http://bzz.no/?page=finnarne
Registered Linux user #86307 (http://counter.li.org)