• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • 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 
00125     whatsThisText = i18n("<qt>This is the icon that will appear in the Places panel.<br /><br />"
00126                          "Click on the button to select a different icon.</qt>");
00127     m_iconButton = new KIconButton( wdg );
00128     layout->addRow( i18n("Choose an &icon:"), m_iconButton );
00129     m_iconButton->setObjectName( QLatin1String( "icon button" ) );
00130     m_iconButton->setIconSize( iconSize );
00131     m_iconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place );
00132     if ( icon.isEmpty() )
00133         m_iconButton->setIcon( KMimeType::iconNameForUrl( url ) );
00134     else
00135         m_iconButton->setIcon( icon );
00136     m_iconButton->setWhatsThis( whatsThisText );
00137     layout->labelForField(m_iconButton)->setWhatsThis( whatsThisText );
00138 
00139     if ( allowGlobal ) {
00140         QString appName;
00141         if ( KGlobal::mainComponent().aboutData() )
00142             appName = KGlobal::mainComponent().aboutData()->programName();
00143         if ( appName.isEmpty() )
00144             appName = KGlobal::mainComponent().componentName();
00145         m_appLocal = new QCheckBox( i18n("&Only show when using this application (%1)",  appName ), wdg );
00146         m_appLocal->setChecked( appLocal );
00147         m_appLocal->setWhatsThis(i18n("<qt>Select this setting if you want this "
00148                               "entry to show only when using the current application (%1).<br /><br />"
00149                               "If this setting is not selected, the entry will be available in all "
00150                               "applications.</qt>",
00151                                appName));
00152         box->addWidget(m_appLocal);
00153     }
00154     else
00155         m_appLocal = 0L;
00156     connect(m_urlEdit->lineEdit(),SIGNAL(textChanged ( const QString & )),this,SLOT(urlChanged(const QString & )));
00157     if (!label.isEmpty()) {
00158         // editing existing entry
00159         m_labelEdit->setFocus();
00160     } else {
00161         // new entry
00162         m_urlEdit->setFocus();
00163     }
00164     setMainWidget( wdg );
00165 }
00166 
00167 KFilePlaceEditDialog::~KFilePlaceEditDialog()
00168 {
00169 }
00170 
00171 void KFilePlaceEditDialog::urlChanged(const QString & text )
00172 {
00173     enableButtonOk( !text.isEmpty() );
00174 }
00175 
00176 KUrl KFilePlaceEditDialog::url() const
00177 {
00178     return m_urlEdit->url();
00179 }
00180 
00181 QString KFilePlaceEditDialog::label() const
00182 {
00183     if (!m_labelEdit->text().isEmpty()) {
00184         return m_labelEdit->text();
00185     }
00186 
00187     // derive descriptive label from the URL
00188     KUrl url = m_urlEdit->url();
00189     if (!url.fileName().isEmpty()) {
00190         return url.fileName();
00191     }
00192     if (!url.host().isEmpty()) {
00193         return url.host();
00194     }
00195     return url.scheme();
00196 }
00197 
00198 const QString &KFilePlaceEditDialog::icon() const
00199 {
00200     return m_iconButton->icon();
00201 }
00202 
00203 bool KFilePlaceEditDialog::applicationLocal() const
00204 {
00205     if ( !m_appLocal )
00206         return true;
00207 
00208     return m_appLocal->isChecked();
00209 }
00210 
00211 
00212 #include "kfileplaceeditdialog.moc"

KFile

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal