]> cloud.milkyroute.net Git - dolphin.git/blob - src/editbookmarkdialog.cpp
compile++
[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::slotButtonClicked(int button)
51 {
52 if (button==Ok) {
53 m_bookmark = KBookmark::standaloneBookmark(m_name->text(),
54 KUrl(m_location->text()),
55 m_iconName);
56 }
57
58 KDialog::slotButtonClicked(button);
59 }
60
61 EditBookmarkDialog::EditBookmarkDialog(const QString& title,
62 const QString& name,
63 const KUrl& url,
64 const QString& icon) :
65 KDialog(),
66 m_iconButton(0),
67 m_name(0),
68 m_location(0)
69 {
70 setCaption(title);
71 setButtons(Ok|Cancel);
72 setDefaultButton(Ok);
73
74 QWidget *page = new QWidget(this);
75 setMainWidget(page);
76
77 Q3VBoxLayout* topLayout = new Q3VBoxLayout(page, 0, spacingHint());
78
79 Q3Grid* grid = new Q3Grid(2, Qt::Horizontal, page);
80 grid->setSpacing(spacingHint());
81
82 // create icon widgets
83 new QLabel(i18n("Icon:"), grid);
84 m_iconName = icon;
85 m_iconButton = new QPushButton(SmallIcon(m_iconName), QString::null, grid);
86 m_iconButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
87 connect(m_iconButton, SIGNAL(clicked()),
88 this, SLOT(selectIcon()));
89
90 // create name widgets
91 new QLabel(i18n("Name:"), grid);
92 m_name = new QLineEdit(name, grid);
93 m_name->selectAll();
94 m_name->setFocus();
95
96 // create location widgets
97 new QLabel(i18n("Location:"), grid);
98
99 Q3HBox* locationBox = new Q3HBox(grid);
100 locationBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
101 locationBox->setSpacing(spacingHint());
102 m_location = new QLineEdit(url.prettyUrl(), locationBox);
103 m_location->setMinimumWidth(320);
104
105 QPushButton* selectLocationButton = new QPushButton(SmallIcon("folder"), QString::null, locationBox);
106 selectLocationButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
107 connect(selectLocationButton, SIGNAL(clicked()),
108 this, SLOT(selectLocation()));
109
110 topLayout->addWidget(grid);
111 }
112
113 void EditBookmarkDialog::selectIcon()
114 {
115 const QString iconName(KIconDialog::getIcon(K3Icon::Small, K3Icon::FileSystem));
116 if (!iconName.isEmpty()) {
117 m_iconName = iconName;
118 m_iconButton->setIconSet(SmallIcon(iconName));
119 }
120 }
121
122 void EditBookmarkDialog::selectLocation()
123 {
124 const QString location(m_location->text());
125 KUrl url(KFileDialog::getExistingUrl(location));
126 if (!url.isEmpty()) {
127 m_location->setText(url.prettyUrl());
128 }
129 }
130
131 #include "editbookmarkdialog.moc"