• Skip to content
  • Skip to link menu
KDE 4.3 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().toLocalFile());
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 
00109     foreach (const KFileMetaInfoGroup& group, groupList) {
00110         //kDebug(7033) << *git;
00111 
00112         KFileMetaInfoItemList itemList = group.items();
00113         if (itemList.isEmpty())
00114             continue;
00115 
00116         QGroupBox *groupBox = new QGroupBox( Qt::escape(group.name()),
00117             d->m_frame);
00118         QGridLayout *grouplayout = new QGridLayout(groupBox);
00119         grouplayout->activate();
00120 
00121         toplayout->addWidget(groupBox);
00122 
00123         KFileMetaInfoItemList readItems;
00124         KFileMetaInfoItemList editItems;
00125 
00126         foreach (const KFileMetaInfoItem& item, itemList) {
00127             if ( !item.isValid() ) continue;
00128 
00129             bool editable = file_info.isWritable() && item.isEditable();
00130 
00131             if (editable)
00132                 editItems.append( item );
00133             else
00134                 readItems.append( item );
00135         }
00136 
00137         KFileMetaInfoWidget* w = 0L;
00138         int row = 0;
00139         // then first add the editable items to the layout
00140         foreach (const KFileMetaInfoItem& item, editItems) {
00141             QLabel* l = new QLabel(item.name() + ':', groupBox);
00142             grouplayout->addWidget(l, row, 0);
00143             l->setAlignment( Qt::AlignLeft | Qt::AlignTop );
00144             QValidator* val = item.properties().createValidator();
00145             if (!val) kDebug(7033) << "didn't get a validator for "
00146                 << item.name() << endl;
00147             w = new KFileMetaInfoWidget(item, val, groupBox);
00148             grouplayout->addWidget(w, row, 1);
00149             d->m_editWidgets.append( w );
00150             connect(w, SIGNAL(valueChanged(const QVariant&)), this, SIGNAL(changed()));
00151             ++row;
00152         }
00153 
00154         // and then the read only items
00155         foreach (const KFileMetaInfoItem& item, readItems) {
00156             QLabel* l = new QLabel(item.name() + ':', groupBox);
00157             grouplayout->addWidget(l, row, 0);
00158             l->setAlignment( Qt::AlignLeft | Qt::AlignTop );
00159             w = new KFileMetaInfoWidget(item, KFileMetaInfoWidget::ReadOnly, 0L, groupBox);
00160             grouplayout->addWidget(w, row, 1);
00161             ++row;
00162         }
00163     }
00164 
00165     toplayout->addStretch(1);
00166 
00167     // the add key (disabled until fully implemented)
00168 /*    d->m_add = new QPushButton(i18n("&Add"), topframe);
00169     d->m_add->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
00170                                         QSizePolicy::Fixed));
00171     connect(d->m_add, SIGNAL(clicked()), this, SLOT(slotAdd()));
00172     tmp->addWidget(d->m_add);
00173 
00174     // if nothing can be added, deactivate it
00175     if ( !d->m_info.supportsVariableKeys() )
00176     {
00177         // if supportedKeys() does contain anything not in preferredKeys,
00178         // we have something addable
00179 
00180         QStringList sk = d->m_info.supportedKeys();
00181         d->m_add->setEnabled(false);
00182         for (QStringList::const_iterator it = sk.begin(); it!=sk.end(); ++it)
00183         {
00184                 if ( l.find(*it)==l.end() )
00185                 {
00186                     d->m_add->setEnabled(true);
00187                     kDebug(250) << "**first addable key is " << (*it).toLatin1().constData() << "**";
00188                     break;
00189                 }
00190                 kDebug(250) << "**already existing key is " << (*it).toLatin1().constData() << "**";
00191         }
00192     } */
00193 }
00194 
00195 /*void KFileMetaPropsPlugin::slotAdd()
00196 {
00197     // add a lineedit for the name
00198 
00199 
00200 
00201     // insert the item in the list
00202 
00203 }*/
00204 
00205 KFileMetaPropsPlugin::~KFileMetaPropsPlugin()
00206 {
00207     delete d;
00208 }
00209 
00210 bool KFileMetaPropsPlugin::supports( const KFileItemList& _items )
00211 {
00212     kDebug() ;
00213 
00214     // TODO: Add support for more than one item
00215 
00216     // TODO check that KDesktopPropsPlugin is correct, i.e. that we never want metainfo for
00217     // a .desktop file? Used to be that only Application desktop files were filtered out
00218     if (KDesktopPropsPlugin::supports(_items) || KUrlPropsPlugin::supports(_items))
00219         return false; // Having both is redundant.
00220     if (_items.count() != 1)
00221         return false;
00222 
00223     bool metaDataEnabled = KGlobalSettings::showFilePreview(_items.first().url());
00224     kDebug() << "metaDataEnabled=" << metaDataEnabled;
00225     return metaDataEnabled;
00226 }
00227 
00228 void KFileMetaPropsPlugin::applyChanges()
00229 {
00230     kDebug(250) << "applying changes";
00231     // insert the fields that changed into the info object
00232 
00233     foreach(KFileMetaInfoWidget* w, d->m_editWidgets)
00234         w->apply();
00235     d->m_info.applyChanges();
00236 }
00237 
00238 #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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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