You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.5 KiB
112 lines
3.5 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2001 Waldo Bastian <bastian@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
14 years ago
|
#include <tqimage.h>
|
||
|
#include <tqregexp.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kiconloader.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
|
||
|
#include "kcustommenu.h"
|
||
|
|
||
|
class KCustomMenu::KCustomMenuPrivate
|
||
|
{
|
||
|
public:
|
||
14 years ago
|
TQMap<int,KService::Ptr> entryMap;
|
||
15 years ago
|
};
|
||
|
|
||
14 years ago
|
KCustomMenu::KCustomMenu(const TQString &configfile, TQWidget *parent)
|
||
|
: TQPopupMenu(parent, "kcustom_menu")
|
||
15 years ago
|
{
|
||
|
d = new KCustomMenuPrivate;
|
||
|
|
||
12 years ago
|
TDEConfig cfg(configfile, true, false);
|
||
15 years ago
|
int count = cfg.readNumEntry("NrOfItems");
|
||
|
for(int i = 0; i < count; i++)
|
||
|
{
|
||
14 years ago
|
TQString entry = cfg.readEntry(TQString("Item%1").arg(i+1));
|
||
15 years ago
|
if (entry.isEmpty())
|
||
|
continue;
|
||
|
|
||
|
// Try KSycoca first.
|
||
|
KService::Ptr menuItem = KService::serviceByDesktopPath( entry );
|
||
|
if (!menuItem)
|
||
|
menuItem = KService::serviceByDesktopName( entry );
|
||
|
if (!menuItem)
|
||
|
menuItem = new KService( entry );
|
||
|
|
||
|
if (!menuItem->isValid())
|
||
|
continue;
|
||
|
|
||
|
insertMenuItem( menuItem, -1 );
|
||
|
}
|
||
14 years ago
|
connect(this, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotActivated(int)));
|
||
15 years ago
|
}
|
||
|
|
||
|
KCustomMenu::~KCustomMenu()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
KCustomMenu::slotActivated(int id)
|
||
|
{
|
||
|
KService::Ptr s = d->entryMap[id];
|
||
|
if (!s)
|
||
|
return;
|
||
|
kapp->startServiceByDesktopPath(s->desktopEntryPath());
|
||
|
}
|
||
|
|
||
|
// The following is copied from kicker's PanelServiceMenu
|
||
|
void
|
||
|
KCustomMenu::insertMenuItem(KService::Ptr & s, int nId, int nIndex/*= -1*/)
|
||
|
{
|
||
14 years ago
|
TQString serviceName = s->name();
|
||
15 years ago
|
|
||
|
// item names may contain ampersands. To avoid them being converted
|
||
14 years ago
|
// to accelators, replace them with two ampersands.
|
||
13 years ago
|
serviceName.replace("&", "&&");
|
||
15 years ago
|
|
||
12 years ago
|
TQPixmap normal = TDEGlobal::instance()->iconLoader()->loadIcon(s->icon(), TDEIcon::Small,
|
||
|
0, TDEIcon::DefaultState, 0L, true);
|
||
|
TQPixmap active = TDEGlobal::instance()->iconLoader()->loadIcon(s->icon(), TDEIcon::Small,
|
||
|
0, TDEIcon::ActiveState, 0L, true);
|
||
15 years ago
|
// make sure they are not larger than 16x16
|
||
|
if (normal.width() > 16 || normal.height() > 16) {
|
||
14 years ago
|
TQImage tmp = normal.convertToImage();
|
||
15 years ago
|
tmp = tmp.smoothScale(16, 16);
|
||
|
normal.convertFromImage(tmp);
|
||
|
}
|
||
|
if (active.width() > 16 || active.height() > 16) {
|
||
14 years ago
|
TQImage tmp = active.convertToImage();
|
||
15 years ago
|
tmp = tmp.smoothScale(16, 16);
|
||
|
active.convertFromImage(tmp);
|
||
|
}
|
||
|
|
||
14 years ago
|
TQIconSet iconset;
|
||
|
iconset.setPixmap(normal, TQIconSet::Small, TQIconSet::Normal);
|
||
|
iconset.setPixmap(active, TQIconSet::Small, TQIconSet::Active);
|
||
15 years ago
|
|
||
|
int newId = insertItem(iconset, serviceName, nId, nIndex);
|
||
|
d->entryMap.insert(newId, s);
|
||
|
}
|
||
|
|
||
|
#include "kcustommenu.moc"
|