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

KFile

  • kfile
knameandurlinputdialog.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 "knameandurlinputdialog.h"
22
23#include <klineedit.h>
24#include <kurlrequester.h>
25#include <kprotocolmanager.h>
26#include <QFormLayout>
27#include <QLabel>
28
29class KNameAndUrlInputDialogPrivate
30{
31public:
32 KNameAndUrlInputDialogPrivate(KNameAndUrlInputDialog* qq) : m_fileNameEdited(false), q(qq) {}
33
34 void _k_slotNameTextChanged(const QString&);
35 void _k_slotURLTextChanged(const QString&);
36
40 KLineEdit *m_leName;
44 KUrlRequester *m_urlRequester;
48 bool m_fileNameEdited;
49 KNameAndUrlInputDialog* q;
50};
51
52KNameAndUrlInputDialog::KNameAndUrlInputDialog(const QString& nameLabel, const QString& urlLabel, const KUrl& startDir, QWidget *parent)
53 : KDialog(parent), d(new KNameAndUrlInputDialogPrivate(this))
54{
55 setButtons(Ok | Cancel);
56
57 QWidget* plainPage = new QWidget(this);
58 setMainWidget(plainPage);
59
60 QFormLayout* topLayout = new QFormLayout(plainPage);
61 topLayout->setMargin(0);
62
63 // First line: filename
64 d->m_leName = new KLineEdit;
65 d->m_leName->setMinimumWidth(d->m_leName->sizeHint().width() * 3);
66 d->m_leName->setSelection(0, d->m_leName->text().length()); // autoselect
67 connect(d->m_leName, SIGNAL(textChanged(QString)),
68 SLOT(_k_slotNameTextChanged(QString)));
69 topLayout->addRow(nameLabel, d->m_leName);
70
71 // Second line: url
72 d->m_urlRequester = new KUrlRequester;
73 d->m_urlRequester->setStartDir(startDir);
74 d->m_urlRequester->setMode(KFile::File | KFile::Directory);
75
76 d->m_urlRequester->setMinimumWidth(d->m_urlRequester->sizeHint().width() * 3);
77 connect(d->m_urlRequester->lineEdit(), SIGNAL(textChanged(QString)),
78 SLOT(_k_slotURLTextChanged(QString)));
79 topLayout->addRow(urlLabel, d->m_urlRequester);
80
81 d->m_fileNameEdited = false;
82 enableButtonOk(!d->m_leName->text().isEmpty() && !d->m_urlRequester->url().isEmpty());
83 d->m_leName->setFocus();
84}
85
86KNameAndUrlInputDialog::~KNameAndUrlInputDialog()
87{
88 delete d;
89}
90
91KUrl KNameAndUrlInputDialog::url() const
92{
93 if (result() == QDialog::Accepted) {
94 return d->m_urlRequester->url();
95 }
96 else
97 return KUrl();
98}
99
100QString KNameAndUrlInputDialog::name() const
101{
102 if (result() == QDialog::Accepted)
103 return d->m_leName->text();
104 else
105 return QString();
106}
107
108void KNameAndUrlInputDialogPrivate::_k_slotNameTextChanged(const QString&)
109{
110 m_fileNameEdited = true;
111 q->enableButtonOk(!m_leName->text().isEmpty() && !m_urlRequester->url().isEmpty());
112}
113
114void KNameAndUrlInputDialogPrivate::_k_slotURLTextChanged(const QString&)
115{
116 if (!m_fileNameEdited) {
117 // use URL as default value for the filename
118 // (we copy only its filename if protocol supports listing,
119 // but for HTTP we don't want tons of index.html links)
120 KUrl url(m_urlRequester->url());
121 if (KProtocolManager::supportsListing(url) && !url.fileName().isEmpty())
122 m_leName->setText(url.fileName());
123 else
124 m_leName->setText(url.url());
125 m_fileNameEdited = false; // slotNameTextChanged set it to true erroneously
126 }
127 q->enableButtonOk(!m_leName->text().isEmpty() && !m_urlRequester->url().isEmpty());
128}
129
130void KNameAndUrlInputDialog::setSuggestedName(const QString& name)
131{
132 d->m_leName->setText(name);
133 d->m_urlRequester->setFocus();
134}
135
136void KNameAndUrlInputDialog::setSuggestedUrl(const KUrl& url)
137{
138 d->m_urlRequester->setUrl(url);
139}
140
141#include "knameandurlinputdialog.moc"
KDialog
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
KDialog::enableButtonOk
void enableButtonOk(bool state)
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
KDialog::Ok
Ok
KDialog::Cancel
Cancel
KFile::Directory
Directory
KFile::File
File
KLineEdit
KNameAndUrlInputDialog
Dialog to ask for a name (e.g.
Definition: knameandurlinputdialog.h:37
KNameAndUrlInputDialog::~KNameAndUrlInputDialog
virtual ~KNameAndUrlInputDialog()
Destructor.
Definition: knameandurlinputdialog.cpp:86
KNameAndUrlInputDialog::KNameAndUrlInputDialog
KNameAndUrlInputDialog(const QString &nameLabel, const QString &urlLabel, const KUrl &startDir, QWidget *parent)
Definition: knameandurlinputdialog.cpp:52
KNameAndUrlInputDialog::setSuggestedName
void setSuggestedName(const QString &name)
Pre-fill the name lineedit.
Definition: knameandurlinputdialog.cpp:130
KNameAndUrlInputDialog::setSuggestedUrl
void setSuggestedUrl(const KUrl &url)
Pre-fill the URL requester.
Definition: knameandurlinputdialog.cpp:136
KNameAndUrlInputDialog::name
QString name() const
Definition: knameandurlinputdialog.cpp:100
KNameAndUrlInputDialog::url
KUrl url() const
Definition: knameandurlinputdialog.cpp:91
KProtocolManager::supportsListing
static bool supportsListing(const KUrl &url)
KUrlRequester
KUrl
QWidget
klineedit.h
knameandurlinputdialog.h
kprotocolmanager.h
kurlrequester.h
name
const char * name(StandardAction 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.

KFile

Skip menu "KFile"
  • Main Page
  • 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