• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kfile
kurlrequesterdialog.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Wilco Greven <greven@kde.org>
3
4 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; either
7 version 2 of the License, or (at your option) any later version.
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 "kurlrequesterdialog.h"
21
22#include <QtGui/QLabel>
23#include <QtGui/QLayout>
24
25#include <kfiledialog.h>
26#include <klineedit.h>
27#include <klocale.h>
28#include <krecentdocument.h>
29#include <kurl.h>
30#include <kurlrequester.h>
31
32class KUrlRequesterDialogPrivate
33{
34public:
35 KUrlRequesterDialogPrivate(KUrlRequesterDialog *qq)
36 : q(qq)
37 {
38 }
39
40 KUrlRequesterDialog *q;
41
42 void initDialog(const QString &text, const QString &url);
43
44 // slots
45 void _k_slotClear();
46 void _k_slotTextChanged(const QString &);
47
48 KUrlRequester *urlRequester;
49};
50
51
52KUrlRequesterDialog::KUrlRequesterDialog( const QString& urlName, QWidget *parent)
53 : KDialog(parent), d(new KUrlRequesterDialogPrivate(this))
54{
55 setButtons( Ok | Cancel | User1 );
56 setButtonGuiItem( User1, KStandardGuiItem::clear() );
57
58 d->initDialog(i18n("Location:"), urlName);
59}
60
61KUrlRequesterDialog::KUrlRequesterDialog( const QString& urlName, const QString& _text, QWidget *parent)
62 : KDialog(parent), d(new KUrlRequesterDialogPrivate(this))
63{
64 setButtons( Ok | Cancel | User1 );
65 setButtonGuiItem( User1, KStandardGuiItem::clear() );
66
67 d->initDialog(_text, urlName);
68}
69
70KUrlRequesterDialog::~KUrlRequesterDialog()
71{
72 delete d;
73}
74
75void KUrlRequesterDialogPrivate::initDialog(const QString &text,const QString &urlName)
76{
77 q->setDefaultButton(KDialog::Ok);
78 QWidget *plainPage = q->mainWidget();
79 QVBoxLayout * topLayout = new QVBoxLayout( plainPage );
80 topLayout->setMargin( 0 );
81
82 QLabel * label = new QLabel( text , plainPage );
83 topLayout->addWidget( label );
84
85 urlRequester = new KUrlRequester(urlName, plainPage);
86 urlRequester->setMinimumWidth(urlRequester->sizeHint().width() * 3);
87 topLayout->addWidget(urlRequester);
88 urlRequester->setFocus();
89 QObject::connect(urlRequester->lineEdit(), SIGNAL(textChanged(QString)),
90 q, SLOT(_k_slotTextChanged(QString)));
91 bool state = !urlName.isEmpty();
92 q->enableButtonOk(state);
93 q->enableButton(KDialog::User1, state);
94 /*
95 KFile::Mode mode = static_cast<KFile::Mode>( KFile::File |
96 KFile::ExistingOnly );
97 urlRequester_->setMode( mode );
98 */
99 QObject::connect(q, SIGNAL(user1Clicked()), q, SLOT(_k_slotClear()));
100}
101
102void KUrlRequesterDialogPrivate::_k_slotTextChanged(const QString & text)
103{
104 bool state = !text.trimmed().isEmpty();
105 q->enableButtonOk(state);
106 q->enableButton(KDialog::User1, state);
107}
108
109void KUrlRequesterDialogPrivate::_k_slotClear()
110{
111 urlRequester->clear();
112}
113
114KUrl KUrlRequesterDialog::selectedUrl() const
115{
116 if ( result() == QDialog::Accepted )
117 return d->urlRequester->url();
118 else
119 return KUrl();
120}
121
122
123KUrl KUrlRequesterDialog::getUrl(const QString& dir, QWidget *parent,
124 const QString& caption)
125{
126 KUrlRequesterDialog dlg(dir, parent);
127
128 dlg.setCaption(caption.isEmpty() ? i18n("Open") : caption);
129
130 dlg.exec();
131
132 const KUrl& url = dlg.selectedUrl();
133 if (url.isValid())
134 KRecentDocument::add(url);
135
136 return url;
137}
138
139KFileDialog * KUrlRequesterDialog::fileDialog()
140{
141 return d->urlRequester->fileDialog();
142}
143
144KUrlRequester * KUrlRequesterDialog::urlRequester()
145{
146 return d->urlRequester;
147}
148
149#include "kurlrequesterdialog.moc"
150
151// vim:ts=4:sw=4:tw=78
KDialog
KDialog::setButtonGuiItem
void setButtonGuiItem(ButtonCode id, const KGuiItem &item)
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
KDialog::Ok
Ok
KDialog::User1
User1
KDialog::Cancel
Cancel
KDialog::setCaption
virtual void setCaption(const QString &caption)
KFileDialog
Provides a user (and developer) friendly way to select files and directories.
Definition: kfiledialog.h:69
KRecentDocument::add
static void add(const KUrl &url)
Add a new item to the Recent Document menu.
Definition: krecentdocument.cpp:88
KUrlRequesterDialog
Dialog in which a user can enter a filename or url.
Definition: kurlrequesterdialog.h:40
KUrlRequesterDialog::KUrlRequesterDialog
KUrlRequesterDialog(const QString &url, QWidget *parent=0)
Constructs a KUrlRequesterDialog.
Definition: kurlrequesterdialog.cpp:52
KUrlRequesterDialog::fileDialog
KFileDialog * fileDialog()
Returns a pointer to the file dialog used by the KUrlRequester.
Definition: kurlrequesterdialog.cpp:139
KUrlRequesterDialog::urlRequester
KUrlRequester * urlRequester()
Returns a pointer to the KUrlRequester.
Definition: kurlrequesterdialog.cpp:144
KUrlRequesterDialog::selectedUrl
KUrl selectedUrl() const
Returns the fully qualified filename.
Definition: kurlrequesterdialog.cpp:114
KUrlRequesterDialog::getUrl
static KUrl getUrl(const QString &url=QString(), QWidget *parent=0, const QString &caption=QString())
Creates a modal dialog, executes it and returns the selected URL.
Definition: kurlrequesterdialog.cpp:123
KUrlRequesterDialog::~KUrlRequesterDialog
~KUrlRequesterDialog()
Destructs the dialog.
Definition: kurlrequesterdialog.cpp:70
KUrlRequester
This class is a widget showing a lineedit and a button, which invokes a filedialog.
Definition: kurlrequester.h:61
KUrl
QLabel
QWidget
kfiledialog.h
klineedit.h
klocale.h
i18n
QString i18n(const char *text)
krecentdocument.h
kurl.h
kurlrequester.h
kurlrequesterdialog.h
caption
QString caption()
KStandardGuiItem::clear
KGuiItem clear()
label
QString label(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal