23 #include <tqpushbutton.h>
26 #include <kbuttonbox.h>
27 #include <tdelocale.h>
28 #include <tdeglobal.h>
29 #include <kiconloader.h>
30 #include <tdelistview.h>
32 #include <kstandarddirs.h>
33 #include <tdeconfigbase.h>
34 #include <kopenwith.h>
36 #include "kcustommenueditor.h"
38 class KCustomMenuEditor::Item :
public TQListViewItem
41 Item(TQListView *parent, KService::Ptr service)
42 : TQListViewItem(parent),
48 Item(TQListViewItem *parent, KService::Ptr service)
49 : TQListViewItem(parent),
57 TQString serviceName = s->name();
61 serviceName.replace(
"&",
"&&");
63 TQPixmap normal = TDEGlobal::instance()->iconLoader()->loadIcon(s->icon(), TDEIcon::Small,
64 0, TDEIcon::DefaultState, 0L,
true);
67 if (normal.width() > 16 || normal.height() > 16) {
68 TQImage tmp = normal.convertToImage();
69 tmp = tmp.smoothScale(16, 16);
70 normal.convertFromImage(tmp);
72 setText(0, serviceName);
79 class KCustomMenuEditor::KCustomMenuEditorPrivate
82 TQPushButton * pbRemove;
83 TQPushButton * pbMoveUp;
84 TQPushButton * pbMoveDown;
87 KCustomMenuEditor::KCustomMenuEditor(TQWidget *parent)
88 : KDialogBase(parent,
"custommenueditor", true, i18n(
"Menu Editor"), Ok|Cancel, Ok, true),
91 d =
new KCustomMenuEditorPrivate;
92 TQHBox *page = makeHBoxMainWidget();
93 m_listView =
new TDEListView(page);
94 m_listView->addColumn(i18n(
"Menu"));
95 m_listView->setFullWidth(
true);
96 m_listView->setSorting(-1);
97 KButtonBox *buttonBox =
new KButtonBox(page, TQt::Vertical);
98 buttonBox->addButton(i18n(
"New..."),
this, TQ_SLOT(slotNewItem()));
99 d->pbRemove=buttonBox->addButton(i18n(
"Remove"),
this, TQ_SLOT(slotRemoveItem()));
100 d->pbMoveUp=buttonBox->addButton(i18n(
"Move Up"),
this, TQ_SLOT(slotMoveUp()));
101 d->pbMoveDown=buttonBox->addButton(i18n(
"Move Down"),
this, TQ_SLOT(slotMoveDown()));
103 connect( m_listView, TQ_SIGNAL( selectionChanged () ),
this, TQ_SLOT( refreshButton() ) );
107 KCustomMenuEditor::~KCustomMenuEditor()
113 void KCustomMenuEditor::refreshButton()
115 TQListViewItem *item = m_listView->currentItem();
116 d->pbRemove->setEnabled( item );
117 d->pbMoveUp->setEnabled( item && item->itemAbove() );
118 d->pbMoveDown->setEnabled( item && item->itemBelow() );
122 KCustomMenuEditor::load(TDEConfigBase *cfg)
124 cfg->setGroup(TQString::null);
125 int count = cfg->readNumEntry(
"NrOfItems");
126 TQListViewItem *last = 0;
127 for(
int i = 0; i < count; i++)
129 TQString entry = cfg->readPathEntry(TQString(
"Item%1").arg(i+1));
134 KService::Ptr menuItem = KService::serviceByDesktopPath( entry );
136 menuItem = KService::serviceByDesktopName( entry );
138 menuItem =
new KService( entry );
140 if (!menuItem->isValid())
143 TQListViewItem *item =
new Item(m_listView, menuItem);
144 item->moveItem(last);
150 KCustomMenuEditor::save(TDEConfigBase *cfg)
153 TQStringList groups = cfg->groupList();
154 for(TQStringList::ConstIterator it = groups.begin();
155 it != groups.end(); ++it)
157 cfg->deleteGroup(*it);
160 cfg->setGroup(TQString::null);
161 Item * item = (Item *) m_listView->firstChild();
166 TQString path = item->s->desktopEntryPath();
167 if (TQDir::isRelativePath(path) || TQDir::isRelativePath(TDEGlobal::dirs()->relativeLocation(
"xdgdata-apps", path)))
168 path = item->s->desktopEntryName();
169 cfg->writePathEntry(TQString(
"Item%1").arg(i), path);
170 item = (Item *) item->nextSibling();
172 cfg->writeEntry(
"NrOfItems", i);
176 KCustomMenuEditor::slotNewItem()
178 TQListViewItem *item = m_listView->currentItem();
181 dlg.setSaveNewApplications(
true);
185 KService::Ptr s = dlg.service();
186 if (s && s->isValid())
188 Item *newItem =
new Item(m_listView, s);
189 newItem->moveItem(item);
196 KCustomMenuEditor::slotRemoveItem()
198 TQListViewItem *item = m_listView->currentItem();
207 KCustomMenuEditor::slotMoveUp()
209 TQListViewItem *item = m_listView->currentItem();
213 TQListViewItem *searchItem = m_listView->firstChild();
216 TQListViewItem *next = searchItem->nextSibling();
219 searchItem->moveItem(item);
228 KCustomMenuEditor::slotMoveDown()
230 TQListViewItem *item = m_listView->currentItem();
234 TQListViewItem *after = item->nextSibling();
238 item->moveItem( after );
242 #include "kcustommenueditor.moc"