• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

libkonq

  • sources
  • kde-4.12
  • applications
  • kde-baseapps
  • lib
  • konq
konq_nameandurlinputdialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 1998, 2008, 2009 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published by
6  the Free Software Foundation; either version 2 of the License or ( at
7  your option ) version 3 or, at the discretion of KDE e.V. ( which shall
8  act as a proxy as in section 14 of the GPLv3 ), any later version.
9 
10  This library 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 GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "konq_nameandurlinputdialog.h"
22 
23 #include <klineedit.h>
24 #include <kurlrequester.h>
25 #include <kprotocolmanager.h>
26 #include <QLayout>
27 #include <QLabel>
28 
29 class KonqNameAndUrlInputDialogPrivate
30 {
31 public:
32  KonqNameAndUrlInputDialogPrivate(KonqNameAndUrlInputDialog* qq) : m_leName(0), m_urlRequester(0), m_fileNameEdited(false), q(qq) {}
33 
34  void _k_slotClear();
35  void _k_slotNameTextChanged( const QString&);
36  void _k_slotURLTextChanged(const QString&);
37 
41  KLineEdit *m_leName;
45  KUrlRequester *m_urlRequester;
49  bool m_fileNameEdited;
50  KonqNameAndUrlInputDialog* q;
51 };
52 
53 KonqNameAndUrlInputDialog::KonqNameAndUrlInputDialog(const QString& nameLabel, const QString& urlLabel, const KUrl& startDir, QWidget *parent)
54  : KDialog( parent ), d(new KonqNameAndUrlInputDialogPrivate(this))
55 {
56  setButtons( Ok | Cancel | User1 );
57  setButtonGuiItem( User1, KStandardGuiItem::clear() );
58 
59  QFrame *plainPage = new QFrame( this );
60  setMainWidget( plainPage );
61 
62  QVBoxLayout * topLayout = new QVBoxLayout( plainPage );
63  topLayout->setMargin( 0 );
64  topLayout->setSpacing( spacingHint() );
65 
66  // First line: filename
67  KHBox * fileNameBox = new KHBox( plainPage );
68  topLayout->addWidget( fileNameBox );
69 
70  QLabel * label = new QLabel(nameLabel, fileNameBox);
71  d->m_leName = new KLineEdit(fileNameBox);
72  d->m_leName->setMinimumWidth(d->m_leName->sizeHint().width() * 3);
73  label->setBuddy(d->m_leName);
74  d->m_leName->setSelection(0, d->m_leName->text().length()); // autoselect
75  connect(d->m_leName, SIGNAL(textChanged(QString)),
76  SLOT(_k_slotNameTextChanged(QString)));
77 
78  // Second line: url
79  KHBox * urlBox = new KHBox( plainPage );
80  topLayout->addWidget( urlBox );
81  label = new QLabel(urlLabel, urlBox);
82  d->m_urlRequester = new KUrlRequester(urlBox);
83  d->m_urlRequester->setStartDir(startDir);
84  d->m_urlRequester->setMode( KFile::File | KFile::Directory );
85 
86  d->m_urlRequester->setMinimumWidth( d->m_urlRequester->sizeHint().width() * 3 );
87  connect(d->m_urlRequester->lineEdit(), SIGNAL(textChanged(QString)),
88  SLOT(_k_slotURLTextChanged(QString)));
89  label->setBuddy(d->m_urlRequester);
90 
91  connect(this, SIGNAL(user1Clicked()), this, SLOT(_k_slotClear()));
92  d->m_fileNameEdited = false;
93 }
94 
95 KonqNameAndUrlInputDialog::~KonqNameAndUrlInputDialog()
96 {
97  delete d;
98 }
99 
100 KUrl KonqNameAndUrlInputDialog::url() const
101 {
102  if ( result() == QDialog::Accepted ) {
103  return d->m_urlRequester->url();
104  }
105  else
106  return KUrl();
107 }
108 
109 QString KonqNameAndUrlInputDialog::name() const
110 {
111  if ( result() == QDialog::Accepted )
112  return d->m_leName->text();
113  else
114  return QString();
115 }
116 
117 void KonqNameAndUrlInputDialogPrivate::_k_slotClear()
118 {
119  m_leName->clear();
120  m_urlRequester->clear();
121  m_fileNameEdited = false;
122 }
123 
124 void KonqNameAndUrlInputDialogPrivate::_k_slotNameTextChanged( const QString& )
125 {
126  m_fileNameEdited = true;
127  q->enableButtonOk(!m_leName->text().isEmpty() && !m_urlRequester->url().isEmpty());
128 }
129 
130 void KonqNameAndUrlInputDialogPrivate::_k_slotURLTextChanged( const QString& )
131 {
132  if (!m_fileNameEdited) {
133  // use URL as default value for the filename
134  // (we copy only its filename if protocol supports listing,
135  // but for HTTP we don't want tons of index.html links)
136  KUrl url( m_urlRequester->url() );
137  if (KProtocolManager::supportsListing(url) && !url.fileName().isEmpty())
138  m_leName->setText( url.fileName() );
139  else
140  m_leName->setText( url.url() );
141  m_fileNameEdited = false; // slotNameTextChanged set it to true erroneously
142  }
143  q->enableButtonOk(!m_leName->text().isEmpty() && !m_urlRequester->url().isEmpty());
144 }
145 
146 void KonqNameAndUrlInputDialog::setSuggestedName(const QString& name)
147 {
148  d->m_leName->setText(name);
149  d->m_urlRequester->setFocus();
150 }
151 
152 void KonqNameAndUrlInputDialog::setSuggestedUrl(const KUrl& url)
153 {
154  d->m_urlRequester->setUrl(url);
155 }
156 
157 #include "konq_nameandurlinputdialog.moc"
KonqNameAndUrlInputDialog::url
KUrl url() const
Definition: konq_nameandurlinputdialog.cpp:100
KonqNameAndUrlInputDialog::~KonqNameAndUrlInputDialog
virtual ~KonqNameAndUrlInputDialog()
Destructor.
Definition: konq_nameandurlinputdialog.cpp:95
KonqNameAndUrlInputDialog::setSuggestedUrl
void setSuggestedUrl(const KUrl &url)
Pre-fill the URL requester.
Definition: konq_nameandurlinputdialog.cpp:152
QWidget
KonqNameAndUrlInputDialog::name
QString name() const
Definition: konq_nameandurlinputdialog.cpp:109
KDialog
KonqNameAndUrlInputDialog
Dialog to ask for a name (e.g.
Definition: konq_nameandurlinputdialog.h:39
KonqNameAndUrlInputDialog::KonqNameAndUrlInputDialog
KonqNameAndUrlInputDialog(const QString &nameLabel, const QString &urlLabel, const KUrl &startDir, QWidget *parent)
Definition: konq_nameandurlinputdialog.cpp:53
KonqNameAndUrlInputDialog::setSuggestedName
void setSuggestedName(const QString &name)
Pre-fill the name lineedit.
Definition: konq_nameandurlinputdialog.cpp:146
konq_nameandurlinputdialog.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkonq

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Applications
  •   Libraries
  •     libkonq
  • Konsole

Search



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