]> cloud.milkyroute.net Git - dolphin.git/blob - src/editbookmarkdialog.cpp
commited initial version of Dolphin
[dolphin.git] / src / editbookmarkdialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "editbookmarkdialog.h"
22 #include <q3grid.h>
23 //Added by qt3to4:
24 #include <Q3VBoxLayout>
25 #include <klocale.h>
26 #include <qlineedit.h>
27 #include <qlabel.h>
28 #include <qlayout.h>
29 #include <kiconloader.h>
30 #include <qpushbutton.h>
31 #include <kurl.h>
32 #include <kfiledialog.h>
33 #include <kicondialog.h>
34 #include <q3hbox.h>
35
36 EditBookmarkDialog::~EditBookmarkDialog()
37 {
38 }
39
40 KBookmark EditBookmarkDialog::getBookmark(const QString& title,
41 const QString& name,
42 const KURL& url,
43 const QString& icon)
44 {
45 EditBookmarkDialog dialog(title, name, url, icon);
46 dialog.exec();
47 return dialog.m_bookmark;
48 }
49
50 void EditBookmarkDialog::slotOk()
51 {
52 m_bookmark = KBookmark::standaloneBookmark(m_name->text(),
53 KURL(m_location->text()),
54 m_iconName);
55
56 KDialogBase::slotOk();
57 }
58
59 EditBookmarkDialog::EditBookmarkDialog(const QString& title,
60 const QString& name,
61 const KURL& url,
62 const QString& icon) :
63 KDialogBase(Plain, title, Ok|Cancel, Ok),
64 m_iconButton(0),
65 m_name(0),
66 m_location(0)
67 {
68 Q3VBoxLayout* topLayout = new Q3VBoxLayout(plainPage(), 0, spacingHint());
69
70 Q3Grid* grid = new Q3Grid(2, Qt::Horizontal, plainPage());
71 grid->setSpacing(spacingHint());
72
73 // create icon widgets
74 new QLabel(i18n("Icon:"), grid);
75 m_iconName = icon;
76 m_iconButton = new QPushButton(SmallIcon(m_iconName), QString::null, grid);
77 m_iconButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
78 connect(m_iconButton, SIGNAL(clicked()),
79 this, SLOT(selectIcon()));
80
81 // create name widgets
82 new QLabel(i18n("Name:"), grid);
83 m_name = new QLineEdit(name, grid);
84 m_name->selectAll();
85 m_name->setFocus();
86
87 // create location widgets
88 new QLabel(i18n("Location:"), grid);
89
90 Q3HBox* locationBox = new Q3HBox(grid);
91 locationBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
92 locationBox->setSpacing(spacingHint());
93 m_location = new QLineEdit(url.prettyURL(), locationBox);
94 m_location->setMinimumWidth(320);
95
96 QPushButton* selectLocationButton = new QPushButton(SmallIcon("folder"), QString::null, locationBox);
97 selectLocationButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
98 connect(selectLocationButton, SIGNAL(clicked()),
99 this, SLOT(selectLocation()));
100
101 topLayout->addWidget(grid);
102 }
103
104 void EditBookmarkDialog::selectIcon()
105 {
106 const QString iconName(KIconDialog::getIcon(KIcon::Small, KIcon::FileSystem));
107 if (!iconName.isEmpty()) {
108 m_iconName = iconName;
109 m_iconButton->setIconSet(SmallIcon(iconName));
110 }
111 }
112
113 void EditBookmarkDialog::selectLocation()
114 {
115 const QString location(m_location->text());
116 KURL url(KFileDialog::getExistingURL(location));
117 if (!url.isEmpty()) {
118 m_location->setText(url.prettyURL());
119 }
120 }
121
122 #include "editbookmarkdialog.moc"