• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.11.5 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 
32 class KUrlRequesterDialogPrivate
33 {
34 public:
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 
52 KUrlRequesterDialog::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 
61 KUrlRequesterDialog::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 
70 KUrlRequesterDialog::~KUrlRequesterDialog()
71 {
72  delete d;
73 }
74 
75 void 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 
102 void 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 
109 void KUrlRequesterDialogPrivate::_k_slotClear()
110 {
111  urlRequester->clear();
112 }
113 
114 KUrl KUrlRequesterDialog::selectedUrl() const
115 {
116  if ( result() == QDialog::Accepted )
117  return d->urlRequester->url();
118  else
119  return KUrl();
120 }
121 
122 
123 KUrl 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 
139 KFileDialog * KUrlRequesterDialog::fileDialog()
140 {
141  return d->urlRequester->fileDialog();
142 }
143 
144 KUrlRequester * KUrlRequesterDialog::urlRequester()
145 {
146  return d->urlRequester;
147 }
148 
149 #include "kurlrequesterdialog.moc"
150 
151 // vim:ts=4:sw=4:tw=78
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon May 5 2014 18:13:44 by doxygen 1.8.3.1 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.11.5 API Reference

Skip menu "kdelibs-4.11.5 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