• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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/QGridLayout>
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& description, QString& icon,
00056                                           bool& appLocal, int iconSize,
00057                                           QWidget *parent )
00058 {
00059     KFilePlaceEditDialog *dialog = new KFilePlaceEditDialog(allowGlobal, url,
00060                                                             description, icon,
00061                                                             appLocal,
00062                                                             iconSize, parent );
00063     if ( dialog->exec() == QDialog::Accepted ) {
00064         // set the return parameters
00065         url         = dialog->url();
00066         description = dialog->description();
00067         icon        = dialog->icon();
00068         appLocal    = dialog->applicationLocal();
00069 
00070         delete dialog;
00071         return true;
00072     }
00073 
00074     delete dialog;
00075     return false;
00076 }
00077 
00078 KFilePlaceEditDialog::KFilePlaceEditDialog(bool allowGlobal, const KUrl& url,
00079                                            const QString& description,
00080                                            const QString &icon, bool appLocal,
00081                                            int iconSize,
00082                                            QWidget *parent)
00083     : KDialog( parent )
00084 {
00085     setCaption( i18n("Edit Places Entry") );
00086     setButtons( Ok | Cancel );
00087     setModal(true);
00088     setDefaultButton(Ok);
00089     showButtonSeparator(true);
00090 
00091     QWidget *wdg = new QWidget( this );
00092     QVBoxLayout *box = new QVBoxLayout( wdg );
00093     box->setSpacing( spacingHint() );
00094 
00095     QGridLayout *layout = new QGridLayout();
00096     layout->setSpacing( spacingHint() );
00097     box->addLayout( layout );
00098 
00099     QString whatsThisText = i18n("<qt>This is the text that will appear in the Places panel.<br /><br />"
00100                                  "The description should consist of one or two words "
00101                                  "that will help you remember what this entry refers to.</qt>");
00102     QLabel *label = new QLabel( i18n("&Description:"), wdg );
00103     layout->addWidget( label, 0, 0 );
00104 
00105     m_edit = new KLineEdit( wdg );
00106     layout->addWidget( m_edit, 0, 1 );
00107     m_edit->setText( description.isEmpty() ? url.fileName() : description );
00108     label->setBuddy( m_edit );
00109     label->setWhatsThis(whatsThisText );
00110     m_edit->setWhatsThis(whatsThisText );
00111 
00112     whatsThisText = i18n("<qt>This is the location associated with the entry. Any valid URL may be used. For example:<br /><br />"
00113                          "%1<br />http://www.kde.org<br />ftp://ftp.kde.org/pub/kde/stable<br /><br />"
00114                          "By clicking on the button next to the text edit box you can browse to an "
00115                          "appropriate URL.</qt>", QDir::homePath());
00116     label = new QLabel( i18n("&Location:"), wdg );
00117     layout->addWidget( label, 1, 0 );
00118     m_urlEdit = new KUrlRequester( url.prettyUrl(), wdg );
00119     m_urlEdit->setMode( KFile::Directory );
00120     layout->addWidget( m_urlEdit, 1, 1 );
00121     label->setBuddy( m_urlEdit );
00122     label->setWhatsThis(whatsThisText );
00123     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     label = new QLabel( i18n("Choose an &icon:"), wdg );
00128     layout->addWidget( label, 2, 0 );
00129     m_iconButton = new KIconButton( wdg );
00130     layout->addWidget( m_iconButton, 2, 1 );
00131     m_iconButton->setObjectName( QLatin1String( "icon button" ) );
00132     m_iconButton->setIconSize( iconSize );
00133     if ( icon.isEmpty() )
00134         m_iconButton->setIcon( KMimeType::iconNameForUrl( url ) );
00135     else
00136         m_iconButton->setIcon( icon );
00137     label->setBuddy( m_iconButton );
00138     label->setWhatsThis(whatsThisText );
00139     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 ( const QString & )),this,SLOT(urlChanged(const QString & )));
00159     m_edit->setFocus();
00160     setMainWidget( wdg );
00161 }
00162 
00163 KFilePlaceEditDialog::~KFilePlaceEditDialog()
00164 {
00165 }
00166 
00167 void KFilePlaceEditDialog::urlChanged(const QString & text )
00168 {
00169     enableButtonOk( !text.isEmpty() );
00170 }
00171 
00172 KUrl KFilePlaceEditDialog::url() const
00173 {
00174     return m_urlEdit->url();
00175 }
00176 
00177 QString KFilePlaceEditDialog::description() const
00178 {
00179     return m_edit->text();
00180 }
00181 
00182 const QString &KFilePlaceEditDialog::icon() const
00183 {
00184     return m_iconButton->icon();
00185 }
00186 
00187 bool KFilePlaceEditDialog::applicationLocal() const
00188 {
00189     if ( !m_appLocal )
00190         return true;
00191 
00192     return m_appLocal->isChecked();
00193 }
00194 
00195 
00196 #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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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