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

KFile

kfileplaceeditdialog.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org>
00003     Copyright (C) 2007 Kevin Ottens <ervin@kde.org>
00004 
00005     library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation, version 2.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kfileplaceeditdialog.h"
00021 
00022 #include <kaboutdata.h>
00023 #include <kconfig.h>
00024 #include <kdebug.h>
00025 #include <kglobal.h>
00026 #include <kicondialog.h>
00027 #include <kiconloader.h>
00028 #include <kcomponentdata.h>
00029 #include <klineedit.h>
00030 #include <klocale.h>
00031 #include <kmimetype.h>
00032 #include <kio/global.h>
00033 #include <kprotocolinfo.h>
00034 #include <kstringhandler.h>
00035 #include <kurlrequester.h>
00036 
00037 #include <QtCore/QMimeData>
00038 #include <QtGui/QApplication>
00039 #include <QtGui/QCheckBox>
00040 #include <QtGui/qdrawutil.h>
00041 #include <QtGui/QFontMetrics>
00042 #include <QtGui/QFormLayout>
00043 #include <QtGui/QItemDelegate>
00044 #include <QtGui/QLabel>
00045 #include <QtGui/QMenu>
00046 #include <QtGui/QPainter>
00047 #include <QtGui/QStyle>
00048 
00049 #include <unistd.h>
00050 #include <kvbox.h>
00051 #include <kconfiggroup.h>
00052 
00053 
00054 bool KFilePlaceEditDialog::getInformation(bool allowGlobal, KUrl& url,
00055                                           QString& label, QString& icon,
00056                                           bool isAddingNewPlace,
00057                                           bool& appLocal, int iconSize,
00058                                           QWidget *parent )
00059 {
00060     KFilePlaceEditDialog *dialog = new KFilePlaceEditDialog(allowGlobal, url,
00061                                                             label, icon,
00062                                                             isAddingNewPlace,
00063                                                             appLocal,
00064                                                             iconSize,
00065                                                             parent );
00066     if ( dialog->exec() == QDialog::Accepted ) {
00067         // set the return parameters
00068         url         = dialog->url();
00069         label       = dialog->label();
00070         icon        = dialog->icon();
00071         appLocal    = dialog->applicationLocal();
00072 
00073         delete dialog;
00074         return true;
00075     }
00076 
00077     delete dialog;
00078     return false;
00079 }
00080 
00081 KFilePlaceEditDialog::KFilePlaceEditDialog(bool allowGlobal, const KUrl& url,
00082                                            const QString& label,
00083                                            const QString &icon,
00084                                            bool isAddingNewPlace,
00085                                            bool appLocal, int iconSize,
00086                                            QWidget *parent)
00087     : KDialog( parent )
00088 {
00089     if (isAddingNewPlace)
00090         setCaption( i18n("Add Places Entry") );
00091     else
00092         setCaption( i18n("Edit Places Entry") );
00093     setButtons( Ok | Cancel );
00094     setModal(true);
00095     setDefaultButton(Ok);
00096 
00097     QWidget *wdg = new QWidget( this );
00098     QVBoxLayout *box = new QVBoxLayout( wdg );
00099 
00100     QFormLayout *layout = new QFormLayout();
00101     box->addLayout( layout );
00102 
00103     QString whatsThisText = i18n("<qt>This is the text that will appear in the Places panel.<br /><br />"
00104                                  "The label should consist of one or two words "
00105                                  "that will help you remember what this entry refers to. "
00106                                  "If you do not enter a label, it will be derived from "
00107                                  "the location's URL.</qt>");
00108     m_labelEdit = new KLineEdit(wdg);
00109     layout->addRow(i18n("L&abel:"), m_labelEdit);
00110     m_labelEdit->setText(label);
00111     m_labelEdit->setClickMessage(i18n("Enter descriptive label here"));
00112     m_labelEdit->setWhatsThis(whatsThisText);
00113     layout->labelForField(m_labelEdit)->setWhatsThis(whatsThisText);
00114 
00115     whatsThisText = i18n("<qt>This is the location associated with the entry. Any valid URL may be used. For example:<br /><br />"
00116                          "%1<br />http://www.kde.org<br />ftp://ftp.kde.org/pub/kde/stable<br /><br />"
00117                          "By clicking on the button next to the text edit box you can browse to an "
00118                          "appropriate URL.</qt>", QDir::homePath());
00119     m_urlEdit = new KUrlRequester( url.prettyUrl(), wdg );
00120     m_urlEdit->setMode( KFile::Directory );
00121     layout->addRow( i18n("&Location:"), m_urlEdit );
00122     m_urlEdit->setWhatsThis( whatsThisText );
00123     layout->labelForField(m_urlEdit)->setWhatsThis( whatsThisText );
00124     // Room for at least 40 chars (average char width is half of height)
00125     m_urlEdit->setMinimumWidth( m_urlEdit->fontMetrics().height() * (40 / 2) );
00126 
00127     whatsThisText = i18n("<qt>This is the icon that will appear in the Places panel.<br /><br />"
00128                          "Click on the button to select a different icon.</qt>");
00129     m_iconButton = new KIconButton( wdg );
00130     layout->addRow( i18n("Choose an &icon:"), m_iconButton );
00131     m_iconButton->setObjectName( QLatin1String( "icon button" ) );
00132     m_iconButton->setIconSize( iconSize );
00133     m_iconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place );
00134     if ( icon.isEmpty() )
00135         m_iconButton->setIcon( KMimeType::iconNameForUrl( url ) );
00136     else
00137         m_iconButton->setIcon( icon );
00138     m_iconButton->setWhatsThis( whatsThisText );
00139     layout->labelForField(m_iconButton)->setWhatsThis( whatsThisText );
00140 
00141     if ( allowGlobal ) {
00142         QString appName;
00143         if ( KGlobal::mainComponent().aboutData() )
00144             appName = KGlobal::mainComponent().aboutData()->programName();
00145         if ( appName.isEmpty() )
00146             appName = KGlobal::mainComponent().componentName();
00147         m_appLocal = new QCheckBox( i18n("&Only show when using this application (%1)",  appName ), wdg );
00148         m_appLocal->setChecked( appLocal );
00149         m_appLocal->setWhatsThis(i18n("<qt>Select this setting if you want this "
00150                               "entry to show only when using the current application (%1).<br /><br />"
00151                               "If this setting is not selected, the entry will be available in all "
00152                               "applications.</qt>",
00153                                appName));
00154         box->addWidget(m_appLocal);
00155     }
00156     else
00157         m_appLocal = 0L;
00158     connect(m_urlEdit->lineEdit(),SIGNAL(textChanged(QString)),this,SLOT(urlChanged(QString)));
00159     if (!label.isEmpty()) {
00160         // editing existing entry
00161         m_labelEdit->setFocus();
00162     } else {
00163         // new entry
00164         m_urlEdit->setFocus();
00165     }
00166     setMainWidget( wdg );
00167 }
00168 
00169 KFilePlaceEditDialog::~KFilePlaceEditDialog()
00170 {
00171 }
00172 
00173 void KFilePlaceEditDialog::urlChanged(const QString & text )
00174 {
00175     enableButtonOk( !text.isEmpty() );
00176 }
00177 
00178 KUrl KFilePlaceEditDialog::url() const
00179 {
00180     return m_urlEdit->url();
00181 }
00182 
00183 QString KFilePlaceEditDialog::label() const
00184 {
00185     if (!m_labelEdit->text().isEmpty()) {
00186         return m_labelEdit->text();
00187     }
00188 
00189     // derive descriptive label from the URL
00190     KUrl url = m_urlEdit->url();
00191     if (!url.fileName().isEmpty()) {
00192         return url.fileName();
00193     }
00194     if (!url.host().isEmpty()) {
00195         return url.host();
00196     }
00197     return url.scheme();
00198 }
00199 
00200 const QString &KFilePlaceEditDialog::icon() const
00201 {
00202     return m_iconButton->icon();
00203 }
00204 
00205 bool KFilePlaceEditDialog::applicationLocal() const
00206 {
00207     if ( !m_appLocal )
00208         return true;
00209 
00210     return m_appLocal->isChecked();
00211 }
00212 
00213 
00214 #include "kfileplaceeditdialog.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 21:01:44 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KFile

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

kdelibs-4.8.3 API Reference

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