]> cloud.milkyroute.net Git - dolphin.git/blob - src/editbookmarkdialog.cpp
move the QT3_SUPPORT definition only where it's needed
[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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 <kvbox.h>
35
36
37 EditBookmarkDialog::~EditBookmarkDialog()
38 {
39 }
40
41 KBookmark EditBookmarkDialog::getBookmark(const QString& title,
42 const QString& name,
43 const KUrl& url,
44 const QString& icon)
45 {
46 EditBookmarkDialog dialog(title, name, url, icon);
47 dialog.exec();
48 return dialog.m_bookmark;
49 }
50
51 void EditBookmarkDialog::slotButtonClicked(int button)
52 {
53 if (button==Ok) {
54 m_bookmark = KBookmark::standaloneBookmark(m_name->text(),
55 KUrl(m_location->text()),
56 m_iconName);
57 }
58
59 KDialog::slotButtonClicked(button);
60 }
61
62 EditBookmarkDialog::EditBookmarkDialog(const QString& title,
63 const QString& name,
64 const KUrl& url,
65 const QString& icon) :
66 KDialog(),
67 m_iconButton(0),
68 m_name(0),
69 m_location(0)
70 {
71 setCaption(title);
72 setButtons(Ok|Cancel);
73 setDefaultButton(Ok);
74
75 QWidget *page = new QWidget(this);
76 setMainWidget(page);
77
78 Q3VBoxLayout* topLayout = new Q3VBoxLayout(page, 0, spacingHint());
79
80 Q3Grid* grid = new Q3Grid(2, Qt::Horizontal, page);
81 grid->setSpacing(spacingHint());
82
83 // create icon widgets
84 new QLabel(i18n("Icon:"), grid);
85 m_iconName = icon;
86 m_iconButton = new QPushButton(KIcon(m_iconName), QString(), grid);
87 m_iconButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
88 connect(m_iconButton, SIGNAL(clicked()),
89 this, SLOT(selectIcon()));
90
91 // create name widgets
92 new QLabel(i18n("Name:"), grid);
93 m_name = new QLineEdit(name, grid);
94 m_name->selectAll();
95 m_name->setFocus();
96
97 // create location widgets
98 new QLabel(i18n("Location:"), grid);
99
100 KHBox* locationBox = new KHBox(grid);
101 locationBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
102 locationBox->setSpacing(spacingHint());
103 m_location = new QLineEdit(url.prettyUrl(), locationBox);
104 m_location->setMinimumWidth(320);
105
106 QPushButton* selectLocationButton = new QPushButton(KIcon("folder"), QString(), locationBox);
107 selectLocationButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
108 connect(selectLocationButton, SIGNAL(clicked()),
109 this, SLOT(selectLocation()));
110
111 topLayout->addWidget(grid);
112 }
113
114 void EditBookmarkDialog::selectIcon()
115 {
116 const QString iconName(KIconDialog::getIcon(K3Icon::Small, K3Icon::FileSystem));
117 if (!iconName.isEmpty()) {
118 m_iconName = iconName;
119 m_iconButton->setIcon(KIcon(iconName));
120 }
121 }
122
123 void EditBookmarkDialog::selectLocation()
124 {
125 const QString location(m_location->text());
126 KUrl url(KFileDialog::getExistingDirectoryUrl(location));
127 if (!url.isEmpty()) {
128 m_location->setText(url.prettyUrl());
129 }
130 }
131
132 #include "editbookmarkdialog.moc"