• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
kcustommenueditor.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; version 2
7 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include <tqhbox.h>
21#include <tqregexp.h>
22#include <tqimage.h>
23#include <tqpushbutton.h>
24#include <tqdir.h>
25
26#include <kbuttonbox.h>
27#include <tdelocale.h>
28#include <tdeglobal.h>
29#include <kiconloader.h>
30#include <tdelistview.h>
31#include <kservice.h>
32#include <tdestandarddirs.h>
33#include <tdeconfigbase.h>
34#include <kopenwith.h>
35
36#include "kcustommenueditor.h"
37
38class KCustomMenuEditor::Item : public TQListViewItem
39{
40public:
41 Item(TQListView *parent, KService::Ptr service)
42 : TQListViewItem(parent),
43 s(service)
44 {
45 init();
46 }
47
48 Item(TQListViewItem *parent, KService::Ptr service)
49 : TQListViewItem(parent),
50 s(service)
51 {
52 init();
53 }
54
55 void init()
56 {
57 TQString serviceName = s->name();
58
59 // item names may contain ampersands. To avoid them being converted
60 // to accelators, replace them with two ampersands.
61 serviceName.replace("&", "&&");
62
63 TQPixmap normal = TDEGlobal::instance()->iconLoader()->loadIcon(s->icon(), TDEIcon::Small,
64 0, TDEIcon::DefaultState, 0L, true);
65
66 // make sure they are not larger than 16x16
67 if (normal.width() > 16 || normal.height() > 16) {
68 TQImage tmp = normal.convertToImage();
69 tmp = tmp.smoothScale(16, 16);
70 normal.convertFromImage(tmp);
71 }
72 setText(0, serviceName);
73 setPixmap(0, normal);
74 }
75
76 KService::Ptr s;
77};
78
79class KCustomMenuEditor::KCustomMenuEditorPrivate
80{
81public:
82 TQPushButton * pbRemove;
83 TQPushButton * pbMoveUp;
84 TQPushButton * pbMoveDown;
85};
86
87KCustomMenuEditor::KCustomMenuEditor(TQWidget *parent)
88 : KDialogBase(parent, "custommenueditor", true, i18n("Menu Editor"), Ok|Cancel, Ok, true),
89 m_listView(0)
90{
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()));
102 buttonBox->layout();
103 connect( m_listView, TQ_SIGNAL( selectionChanged () ), this, TQ_SLOT( refreshButton() ) );
104 refreshButton();
105}
106
107KCustomMenuEditor::~KCustomMenuEditor()
108{
109 delete d;
110 d=0;
111}
112
113void KCustomMenuEditor::refreshButton()
114{
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() );
119}
120
121void
122KCustomMenuEditor::load(TDEConfigBase *cfg)
123{
124 cfg->setGroup(TQString::null);
125 int count = cfg->readNumEntry("NrOfItems");
126 TQListViewItem *last = 0;
127 for(int i = 0; i < count; i++)
128 {
129 TQString entry = cfg->readPathEntry(TQString("Item%1").arg(i+1));
130 if (entry.isEmpty())
131 continue;
132
133 // Try KSycoca first.
134 KService::Ptr menuItem = KService::serviceByDesktopPath( entry );
135 if (!menuItem)
136 menuItem = KService::serviceByDesktopName( entry );
137 if (!menuItem)
138 menuItem = new KService( entry );
139
140 if (!menuItem->isValid())
141 continue;
142
143 TQListViewItem *item = new Item(m_listView, menuItem);
144 item->moveItem(last);
145 last = item;
146 }
147}
148
149void
150KCustomMenuEditor::save(TDEConfigBase *cfg)
151{
152 // First clear the whole config file.
153 TQStringList groups = cfg->groupList();
154 for(TQStringList::ConstIterator it = groups.begin();
155 it != groups.end(); ++it)
156 {
157 cfg->deleteGroup(*it);
158 }
159
160 cfg->setGroup(TQString::null);
161 Item * item = (Item *) m_listView->firstChild();
162 int i = 0;
163 while(item)
164 {
165 i++;
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();
171 }
172 cfg->writeEntry("NrOfItems", i);
173}
174
175void
176KCustomMenuEditor::slotNewItem()
177{
178 TQListViewItem *item = m_listView->currentItem();
179
180 KOpenWithDlg dlg(this);
181 dlg.setSaveNewApplications(true);
182
183 if (dlg.exec())
184 {
185 KService::Ptr s = dlg.service();
186 if (s && s->isValid())
187 {
188 Item *newItem = new Item(m_listView, s);
189 newItem->moveItem(item);
190 }
191 refreshButton();
192 }
193}
194
195void
196KCustomMenuEditor::slotRemoveItem()
197{
198 TQListViewItem *item = m_listView->currentItem();
199 if (!item)
200 return;
201
202 delete item;
203 refreshButton();
204}
205
206void
207KCustomMenuEditor::slotMoveUp()
208{
209 TQListViewItem *item = m_listView->currentItem();
210 if (!item)
211 return;
212
213 TQListViewItem *searchItem = m_listView->firstChild();
214 while(searchItem)
215 {
216 TQListViewItem *next = searchItem->nextSibling();
217 if (next == item)
218 {
219 searchItem->moveItem(item);
220 break;
221 }
222 searchItem = next;
223 }
224 refreshButton();
225}
226
227void
228KCustomMenuEditor::slotMoveDown()
229{
230 TQListViewItem *item = m_listView->currentItem();
231 if (!item)
232 return;
233
234 TQListViewItem *after = item->nextSibling();
235 if (!after)
236 return;
237
238 item->moveItem( after );
239 refreshButton();
240}
241
242#include "kcustommenueditor.moc"
KOpenWithDlg
"Open with" dialog box.
Definition: kopenwith.h:47

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.9.4
This website is maintained by Timothy Pearson.