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

KIO

kmetaprops.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2001,2002 Rolf Magnus <ramagnus@kde.org>
00003 
00004     library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kmetaprops.h"
00020 #include "kpropertiesdialog_p.h"
00021 
00022 #include <kdebug.h>
00023 #include <kfilemetainfowidget.h>
00024 #include <kfilemetainfo.h>
00025 #include <kglobal.h>
00026 #include <kglobalsettings.h>
00027 #include <klocale.h>
00028 #include <kprotocolinfo.h>
00029 
00030 #include <QtGui/QDoubleValidator>
00031 #include <QtGui/QLayout>
00032 #include <QtGui/QLabel>
00033 #include <QtCore/QFileInfo>
00034 #include <QtCore/QDate>
00035 #include <QtGui/QGroupBox>
00036 #include <QResizeEvent>
00037 #include <QtCore/QLinkedList>
00038 #include <QScrollArea>
00039 #include <QTextDocument>
00040 
00041 using namespace KDEPrivate;
00042 
00043 class KFileMetaPropsPlugin::KFileMetaPropsPluginPrivate
00044 {
00045 public:
00046     KFileMetaPropsPluginPrivate()  {}
00047     ~KFileMetaPropsPluginPrivate() {}
00048 
00049     QWidget*                      m_frame;
00050     QGridLayout*                  m_framelayout;
00051     KFileMetaInfo                 m_info;
00052 //    QPushButton*                m_add;
00053     QList<KFileMetaInfoWidget *> m_editWidgets;
00054 };
00055 
00056 KFileMetaPropsPlugin::KFileMetaPropsPlugin(KPropertiesDialog* props)
00057   : KPropertiesDialogPlugin(props),d(new KFileMetaPropsPluginPrivate)
00058 {
00059 
00060     KFileItem &fileitem = properties->item();
00061     kDebug(250) << "KFileMetaPropsPlugin constructor";
00062 
00063     d->m_info  = fileitem.metaInfo();
00064     if (!d->m_info.isValid())
00065     {
00066         d->m_info = KFileMetaInfo(properties->kurl().path(KUrl::RemoveTrailingSlash));
00067         fileitem.setMetaInfo(d->m_info);
00068     }
00069 
00070     if ( properties->items().count() > 1 )
00071     {
00072         // not yet supported
00073         // we should allow setting values for a list of files. Itt makes sense
00074         // in some cases, like the album of a list of mp3s
00075         return;
00076     }
00077 
00078     createLayout();
00079 
00080     setDirty(true);
00081 }
00082 
00083 void KFileMetaPropsPlugin::createLayout()
00084 {
00085     QFileInfo file_info(properties->item().url().path());
00086 
00087     kDebug(250) << "KFileMetaPropsPlugin::createLayout";
00088 
00089     // is there any valid and non-empty info at all?
00090     if ( !d->m_info.isValid() )
00091         return;
00092 
00093     // now get a list of groups
00094     //KFileMetaInfoProvider* prov = KFileMetaInfoProvider::self();
00095     KFileMetaInfoGroupList groupList = d->m_info.preferredGroups();
00096     if (groupList.isEmpty())
00097         return;
00098 
00099     QScrollArea* scrollArea = new QScrollArea;
00100     scrollArea->setFrameStyle(QFrame::NoFrame);
00101     properties->addPage(scrollArea, i18n("&Meta Info"));
00102 
00103     d->m_frame = new QWidget(scrollArea);
00104     scrollArea->setWidget(d->m_frame);
00105     scrollArea->setWidgetResizable(true);
00106 
00107     QVBoxLayout *toplayout = new QVBoxLayout(d->m_frame);
00108     toplayout->setSpacing(KDialog::spacingHint());
00109 
00110     foreach (const KFileMetaInfoGroup& group, groupList) {
00111         //kDebug(7033) << *git;
00112 
00113         KFileMetaInfoItemList itemList = group.items();
00114         if (itemList.isEmpty())
00115             continue;
00116 
00117         QGroupBox *groupBox = new QGroupBox( Qt::escape(group.name()),
00118             d->m_frame);
00119         QGridLayout *grouplayout = new QGridLayout(groupBox);
00120         grouplayout->activate();
00121 
00122         toplayout->addWidget(groupBox);
00123 
00124         KFileMetaInfoItemList readItems;
00125         KFileMetaInfoItemList editItems;
00126 
00127         foreach (const KFileMetaInfoItem& item, itemList) {
00128             if ( !item.isValid() ) continue;
00129 
00130             bool editable = file_info.isWritable() && item.isEditable();
00131 
00132             if (editable)
00133                 editItems.append( item );
00134             else
00135                 readItems.append( item );
00136         }
00137 
00138         KFileMetaInfoWidget* w = 0L;
00139         int row = 0;
00140         // then first add the editable items to the layout
00141         foreach (const KFileMetaInfoItem& item, editItems) {
00142             QLabel* l = new QLabel(item.name() + ':', groupBox);
00143             grouplayout->addWidget(l, row, 0);
00144             l->setAlignment( Qt::AlignLeft | Qt::AlignTop );
00145             QValidator* val = item.properties().createValidator();
00146             if (!val) kDebug(7033) << "didn't get a validator for "
00147                 << item.name() << endl;
00148             w = new KFileMetaInfoWidget(item, val, groupBox);
00149             grouplayout->addWidget(w, row, 1);
00150             d->m_editWidgets.append( w );
00151             connect(w, SIGNAL(valueChanged(const QVariant&)), this, SIGNAL(changed()));
00152             ++row;
00153         }
00154 
00155         // and then the read only items
00156         foreach (const KFileMetaInfoItem& item, readItems) {
00157             QLabel* l = new QLabel(item.name() + ':', groupBox);
00158             grouplayout->addWidget(l, row, 0);
00159             l->setAlignment( Qt::AlignLeft | Qt::AlignTop );
00160             w = new KFileMetaInfoWidget(item, KFileMetaInfoWidget::ReadOnly, 0L, groupBox);
00161             grouplayout->addWidget(w, row, 1);
00162             ++row;
00163         }
00164     }
00165 
00166     toplayout->addStretch(1);
00167 
00168     // the add key (disabled until fully implemented)
00169 /*    d->m_add = new QPushButton(i18n("&Add"), topframe);
00170     d->m_add->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
00171                                         QSizePolicy::Fixed));
00172     connect(d->m_add, SIGNAL(clicked()), this, SLOT(slotAdd()));
00173     tmp->addWidget(d->m_add);
00174 
00175     // if nothing can be added, deactivate it
00176     if ( !d->m_info.supportsVariableKeys() )
00177     {
00178         // if supportedKeys() does contain anything not in preferredKeys,
00179         // we have something addable
00180 
00181         QStringList sk = d->m_info.supportedKeys();
00182         d->m_add->setEnabled(false);
00183         for (QStringList::Iterator it = sk.begin(); it!=sk.end(); ++it)
00184         {
00185                 if ( l.find(*it)==l.end() )
00186                 {
00187                     d->m_add->setEnabled(true);
00188                     kDebug(250) << "**first addable key is " << (*it).toLatin1().constData() << "**";
00189                     break;
00190                 }
00191                 kDebug(250) << "**already existing key is " << (*it).toLatin1().constData() << "**";
00192         }
00193     } */
00194 }
00195 
00196 /*void KFileMetaPropsPlugin::slotAdd()
00197 {
00198     // add a lineedit for the name
00199 
00200 
00201 
00202     // insert the item in the list
00203 
00204 }*/
00205 
00206 KFileMetaPropsPlugin::~KFileMetaPropsPlugin()
00207 {
00208     delete d;
00209 }
00210 
00211 bool KFileMetaPropsPlugin::supports( const KFileItemList& _items )
00212 {
00213     kDebug() ;
00214 
00215     // TODO: Add support for more than one item
00216 
00217     // TODO check that KDesktopPropsPlugin is correct, i.e. that we never want metainfo for
00218     // a .desktop file? Used to be that only Application desktop files were filtered out
00219     if (KDesktopPropsPlugin::supports(_items) || KUrlPropsPlugin::supports(_items))
00220         return false; // Having both is redundant.
00221     if (_items.count() != 1)
00222         return false;
00223 
00224     bool metaDataEnabled = KGlobalSettings::showFilePreview(_items.first().url());
00225     kDebug() << "metaDataEnabled=" << metaDataEnabled;
00226     return metaDataEnabled;
00227 }
00228 
00229 void KFileMetaPropsPlugin::applyChanges()
00230 {
00231     kDebug(250) << "applying changes";
00232     // insert the fields that changed into the info object
00233 
00234     foreach(KFileMetaInfoWidget* w, d->m_editWidgets)
00235         w->apply();
00236     d->m_info.applyChanges();
00237 }
00238 
00239 #include "kmetaprops.moc"

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • 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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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