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

KFile

  • sources
  • kde-4.14
  • kdelibs
  • kfile
kfileplaceeditdialog.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org>
3  Copyright (C) 2007 Kevin Ottens <ervin@kde.org>
4 
5  library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation, version 2.
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 "kfileplaceeditdialog.h"
21 
22 #include <kaboutdata.h>
23 #include <kconfig.h>
24 #include <kdebug.h>
25 #include <kglobal.h>
26 #include <kicondialog.h>
27 #include <kiconloader.h>
28 #include <kcomponentdata.h>
29 #include <klineedit.h>
30 #include <klocale.h>
31 #include <kmimetype.h>
32 #include <kio/global.h>
33 #include <kprotocolinfo.h>
34 #include <kstringhandler.h>
35 #include <kurlrequester.h>
36 
37 #include <QtCore/QMimeData>
38 #include <QtGui/QApplication>
39 #include <QtGui/QCheckBox>
40 #include <QtGui/qdrawutil.h>
41 #include <QtGui/QFontMetrics>
42 #include <QtGui/QFormLayout>
43 #include <QtGui/QItemDelegate>
44 #include <QtGui/QLabel>
45 #include <QtGui/QMenu>
46 #include <QtGui/QPainter>
47 #include <QtGui/QStyle>
48 
49 #include <unistd.h>
50 #include <kvbox.h>
51 #include <kconfiggroup.h>
52 
53 
54 bool KFilePlaceEditDialog::getInformation(bool allowGlobal, KUrl& url,
55  QString& label, QString& icon,
56  bool isAddingNewPlace,
57  bool& appLocal, int iconSize,
58  QWidget *parent )
59 {
60  KFilePlaceEditDialog *dialog = new KFilePlaceEditDialog(allowGlobal, url,
61  label, icon,
62  isAddingNewPlace,
63  appLocal,
64  iconSize,
65  parent );
66  if ( dialog->exec() == QDialog::Accepted ) {
67  // set the return parameters
68  url = dialog->url();
69  label = dialog->label();
70  icon = dialog->icon();
71  appLocal = dialog->applicationLocal();
72 
73  delete dialog;
74  return true;
75  }
76 
77  delete dialog;
78  return false;
79 }
80 
81 KFilePlaceEditDialog::KFilePlaceEditDialog(bool allowGlobal, const KUrl& url,
82  const QString& label,
83  const QString &icon,
84  bool isAddingNewPlace,
85  bool appLocal, int iconSize,
86  QWidget *parent)
87  : KDialog( parent )
88 {
89  if (isAddingNewPlace)
90  setCaption( i18n("Add Places Entry") );
91  else
92  setCaption( i18n("Edit Places Entry") );
93  setButtons( Ok | Cancel );
94  setModal(true);
95  setDefaultButton(Ok);
96 
97  QWidget *wdg = new QWidget( this );
98  QVBoxLayout *box = new QVBoxLayout( wdg );
99 
100  QFormLayout *layout = new QFormLayout();
101  box->addLayout( layout );
102 
103  QString whatsThisText = i18n("<qt>This is the text that will appear in the Places panel.<br /><br />"
104  "The label should consist of one or two words "
105  "that will help you remember what this entry refers to. "
106  "If you do not enter a label, it will be derived from "
107  "the location's URL.</qt>");
108  m_labelEdit = new KLineEdit(wdg);
109  layout->addRow(i18n("L&abel:"), m_labelEdit);
110  m_labelEdit->setText(label);
111  m_labelEdit->setClickMessage(i18n("Enter descriptive label here"));
112  m_labelEdit->setWhatsThis(whatsThisText);
113  layout->labelForField(m_labelEdit)->setWhatsThis(whatsThisText);
114 
115  whatsThisText = i18n("<qt>This is the location associated with the entry. Any valid URL may be used. For example:<br /><br />"
116  "%1<br />http://www.kde.org<br />ftp://ftp.kde.org/pub/kde/stable<br /><br />"
117  "By clicking on the button next to the text edit box you can browse to an "
118  "appropriate URL.</qt>", QDir::homePath());
119  m_urlEdit = new KUrlRequester( url.prettyUrl(), wdg );
120  m_urlEdit->setMode( KFile::Directory );
121  layout->addRow( i18n("&Location:"), m_urlEdit );
122  m_urlEdit->setWhatsThis( whatsThisText );
123  layout->labelForField(m_urlEdit)->setWhatsThis( whatsThisText );
124  // Room for at least 40 chars (average char width is half of height)
125  m_urlEdit->setMinimumWidth( m_urlEdit->fontMetrics().height() * (40 / 2) );
126 
127  whatsThisText = i18n("<qt>This is the icon that will appear in the Places panel.<br /><br />"
128  "Click on the button to select a different icon.</qt>");
129  m_iconButton = new KIconButton( wdg );
130  layout->addRow( i18n("Choose an &icon:"), m_iconButton );
131  m_iconButton->setObjectName( QLatin1String( "icon button" ) );
132  m_iconButton->setIconSize( iconSize );
133  m_iconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place );
134  if ( icon.isEmpty() )
135  m_iconButton->setIcon( KMimeType::iconNameForUrl( url ) );
136  else
137  m_iconButton->setIcon( icon );
138  m_iconButton->setWhatsThis( whatsThisText );
139  layout->labelForField(m_iconButton)->setWhatsThis( whatsThisText );
140 
141  if ( allowGlobal ) {
142  QString appName;
143  if ( KGlobal::mainComponent().aboutData() )
144  appName = KGlobal::mainComponent().aboutData()->programName();
145  if ( appName.isEmpty() )
146  appName = KGlobal::mainComponent().componentName();
147  m_appLocal = new QCheckBox( i18n("&Only show when using this application (%1)", appName ), wdg );
148  m_appLocal->setChecked( appLocal );
149  m_appLocal->setWhatsThis(i18n("<qt>Select this setting if you want this "
150  "entry to show only when using the current application (%1).<br /><br />"
151  "If this setting is not selected, the entry will be available in all "
152  "applications.</qt>",
153  appName));
154  box->addWidget(m_appLocal);
155  }
156  else
157  m_appLocal = 0L;
158  connect(m_urlEdit->lineEdit(),SIGNAL(textChanged(QString)),this,SLOT(urlChanged(QString)));
159  if (!label.isEmpty()) {
160  // editing existing entry
161  m_labelEdit->setFocus();
162  } else {
163  // new entry
164  m_urlEdit->setFocus();
165  }
166  setMainWidget( wdg );
167 }
168 
169 KFilePlaceEditDialog::~KFilePlaceEditDialog()
170 {
171 }
172 
173 void KFilePlaceEditDialog::urlChanged(const QString & text )
174 {
175  enableButtonOk( !text.isEmpty() );
176 }
177 
178 KUrl KFilePlaceEditDialog::url() const
179 {
180  return m_urlEdit->url();
181 }
182 
183 QString KFilePlaceEditDialog::label() const
184 {
185  if (!m_labelEdit->text().isEmpty()) {
186  return m_labelEdit->text();
187  }
188 
189  // derive descriptive label from the URL
190  KUrl url = m_urlEdit->url();
191  if (!url.fileName().isEmpty()) {
192  return url.fileName();
193  }
194  if (!url.host().isEmpty()) {
195  return url.host();
196  }
197  return url.scheme();
198 }
199 
200 const QString &KFilePlaceEditDialog::icon() const
201 {
202  return m_iconButton->icon();
203 }
204 
205 bool KFilePlaceEditDialog::applicationLocal() const
206 {
207  if ( !m_appLocal )
208  return true;
209 
210  return m_appLocal->isChecked();
211 }
212 
213 
214 #include "kfileplaceeditdialog.moc"
QWidget::layout
QLayout * layout() const
i18n
QString i18n(const char *text)
QWidget
QDialog::setModal
void setModal(bool modal)
kdebug.h
kmimetype.h
KFilePlaceEditDialog::getInformation
static bool getInformation(bool allowGlobal, KUrl &url, QString &label, QString &icon, bool isAddingNewPlace, bool &appLocal, int iconSize, QWidget *parent=0)
A convenience method to show the dialog and retrieve all the properties via the given parameters...
Definition: kfileplaceeditdialog.cpp:54
QLineEdit::text
text
KFile::Directory
KUrlRequester
kconfig.h
QWidget::setMinimumWidth
void setMinimumWidth(int minw)
QUrl::host
QString host() const
kurlrequester.h
QDialog::exec
int exec()
KFilePlaceEditDialog
A dialog that allows editing entries of a KUrlBar ( KUrlBarItem).
Definition: kfileplaceeditdialog.h:41
kiconloader.h
KComponentData::aboutData
const KAboutData * aboutData() const
KIconButton::setIcon
void setIcon(const QString &icon)
KDialog
KIconButton
KIconButton::setIconType
void setIconType(KIconLoader::Group group, KIconLoader::Context context, bool user=false)
KIconButton::setIconSize
void setIconSize(int size)
KIconLoader::Place
KIconLoader::NoGroup
KIconButton::icon
QString icon
klocale.h
global.h
QDir::homePath
QString homePath()
KUrl
Ok
kglobal.h
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
kfileplaceeditdialog.h
KFilePlaceEditDialog::icon
const QString & icon() const
Definition: kfileplaceeditdialog.cpp:200
QWidget::setFocus
void setFocus()
QCheckBox
QObject::setObjectName
void setObjectName(const QString &name)
QString::isEmpty
bool isEmpty() const
QVBoxLayout
KComponentData::componentName
QString componentName() const
kicondialog.h
QString
kvbox.h
QUrl::scheme
QString scheme() const
QFormLayout::addRow
void addRow(QWidget *label, QWidget *field)
KFilePlaceEditDialog::~KFilePlaceEditDialog
~KFilePlaceEditDialog()
Destroys the dialog.
Definition: kfileplaceeditdialog.cpp:169
kprotocolinfo.h
KFilePlaceEditDialog::url
KUrl url() const
Definition: kfileplaceeditdialog.cpp:178
KFilePlaceEditDialog::applicationLocal
bool applicationLocal() const
Definition: kfileplaceeditdialog.cpp:205
Cancel
kstringhandler.h
QAbstractButton::setChecked
void setChecked(bool)
KAboutData::programName
QString programName() const
KLineEdit
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QWidget::fontMetrics
QFontMetrics fontMetrics() const
QLatin1String
KUrl::fileName
QString fileName(const DirectoryOptions &options=IgnoreTrailingSlash) const
QFormLayout::labelForField
QWidget * labelForField(QWidget *field) const
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
QFontMetrics::height
int height() const
QWidget::setCaption
void setCaption(const QString &c)
KGlobal::mainComponent
const KComponentData & mainComponent()
klineedit.h
KLineEdit::setClickMessage
void setClickMessage(const QString &msg)
KFilePlaceEditDialog::KFilePlaceEditDialog
KFilePlaceEditDialog(bool allowGlobal, const KUrl &url, const QString &label, const QString &icon, bool isAddingNewPlace, bool appLocal=true, int iconSize=KIconLoader::SizeMedium, QWidget *parent=0)
Constructs a KFilePlaceEditDialog.
Definition: kfileplaceeditdialog.cpp:81
kaboutdata.h
kcomponentdata.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KLineEdit::setText
virtual void setText(const QString &)
KFilePlaceEditDialog::urlChanged
void urlChanged(const QString &)
Definition: kfileplaceeditdialog.cpp:173
KUrl::prettyUrl
QString prettyUrl(AdjustPathOption trailing=LeaveTrailingSlash) const
kconfiggroup.h
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
QFormLayout
KFilePlaceEditDialog::label
QString label() const
Definition: kfileplaceeditdialog.cpp:183
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:27:26 by doxygen 1.8.7 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 API Reference

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

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