| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kmetaprops.cpp

    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., 59 Temple Place - Suite 330,
    00016     Boston, MA 02111-1307, USA.
    00017
    00018     $Id: kmetaprops.cpp,v 1.26 2002/06/18 08:25:21 ramagnus Exp $
    00019  */
    00020
    00021 #include "kmetaprops.h"
    00022
    00023 #include <kfilemetainfo.h>
    00024 #include <kglobal.h>
    00025 #include <klocale.h>
    00026 #include <kdebug.h>
    00027 #include <kfilemetainfowidget.h>
    00028
    00029 #include <qvalidator.h>
    00030 #include <qlayout.h>
    00031 #include <qlabel.h>
    00032 #include <qfileinfo.h>
    00033 #include <qdatetime.h>
    00034 #include <qstylesheet.h>
    00035 #include <qvgroupbox.h>
    00036
    00037 #undef Bool
    00038
    00039 class MetaPropsScrollView : public QScrollView
    00040 {
    00041 public:
    00042     MetaPropsScrollView(QWidget* parent = 0, const char* name = 0)
    00043         : QScrollView(parent, name)
    00044     {
    00045       setFrameStyle(QFrame::NoFrame);
    00046       m_frame = new QFrame(viewport(), "MetaPropsScrollView::m_frame");
    00047       m_frame->setFrameStyle(QFrame::NoFrame);
    00048       addChild(m_frame, 0, 0);
    00049     };
    00050
    00051     QFrame* frame() {return m_frame;};
    00052
    00053 protected:
    00054     virtual void viewportResizeEvent(QResizeEvent* ev)
    00055     {
    00056       QScrollView::viewportResizeEvent(ev);
    00057       m_frame->resize( kMax(m_frame->sizeHint().width(), ev->size().width()),
    00058                        kMax(m_frame->sizeHint().height(), ev->size().height()));
    00059     };
    00060
    00061 private:
    00062       QFrame* m_frame;
    00063 };
    00064
    00065 class KFileMetaPropsPlugin::KFileMetaPropsPluginPrivate
    00066 {
    00067 public:
    00068     KFileMetaPropsPluginPrivate()  {}
    00069     ~KFileMetaPropsPluginPrivate() {}
    00070
    00071     QFrame*                       m_frame;
    00072     QGridLayout*                  m_framelayout;
    00073     KFileMetaInfo                 m_info;
    00074 //    QPushButton*                m_add;
    00075     QPtrList<KFileMetaInfoWidget> m_editWidgets;
    00076 };
    00077
    00078 KFileMetaPropsPlugin::KFileMetaPropsPlugin(KPropertiesDialog* props)
    00079   : KPropsDlgPlugin(props)
    00080 {
    00081     d = new KFileMetaPropsPluginPrivate;
    00082
    00083     KFileItem * fileitem = properties->item();
    00084     kdDebug(250) << "KFileMetaPropsPlugin constructor" << endl;
    00085
    00086     d->m_info  = fileitem->metaInfo();
    00087     if (!d->m_info.isValid())
    00088     {
    00089         d->m_info = KFileMetaInfo(properties->kurl().path(-1));
    00090         fileitem->setMetaInfo(d->m_info);
    00091     }
    00092
    00093     if ( properties->items().count() > 1 )
    00094     {
    00095         // not yet supported
    00096         // we should allow setting values for a list of files. Itt makes sense
    00097         // in some cases, like the album of a list of mp3s
    00098         return;
    00099     }
    00100
    00101     createLayout();
    00102
    00103     setDirty(true);
    00104 }
    00105
    00106 void KFileMetaPropsPlugin::createLayout()
    00107 {
    00108     QFileInfo file_info(properties->item()->url().path());
    00109
    00110     kdDebug(250) << "KFileMetaPropsPlugin::createLayout" << endl;
    00111
    00112     // is there any valid and non-empty info at all?
    00113     if ( !d->m_info.isValid() || (d->m_info.preferredKeys()).isEmpty() )
    00114         return;
    00115
    00116     // now get a list of groups
    00117     KFileMetaInfoProvider* prov = KFileMetaInfoProvider::self();
    00118     QStringList groupList = d->m_info.preferredGroups();
    00119
    00120     const KFileMimeTypeInfo* mtinfo = prov->mimeTypeInfo(d->m_info.mimeType());
    00121     if (!mtinfo)
    00122     {
    00123         kdDebug(7034) << "no mimetype info there\n";
    00124         return;
    00125     }
    00126
    00127     // let the dialog create the page frame
    00128     QFrame* topframe = properties->dialog()->addPage(i18n("&Meta Info"));
    00129     topframe->setFrameStyle(QFrame::NoFrame);
    00130     QVBoxLayout* tmp = new QVBoxLayout(topframe);
    00131
    00132     // create a scroll view in the page
    00133     MetaPropsScrollView* view = new MetaPropsScrollView(topframe);
    00134
    00135     tmp->addWidget(view);
    00136
    00137     d->m_frame = view->frame();
    00138
    00139     QVBoxLayout *toplayout = new QVBoxLayout(d->m_frame);
    00140     toplayout->setSpacing(KDialog::spacingHint());
    00141
    00142     for (QStringList::Iterator git=groupList.begin();
    00143             git!=groupList.end(); ++git)
    00144     {
    00145         kdDebug(7033) << *git << endl;
    00146
    00147         QStringList itemList = d->m_info.group(*git).preferredKeys();
    00148         if (itemList.isEmpty())
    00149             continue;
    00150
    00151         QGroupBox *groupBox = new QGroupBox(2, Qt::Horizontal,
    00152             QStyleSheet::escape(mtinfo->groupInfo(*git)->translatedName()),
    00153             d->m_frame);
    00154
    00155         toplayout->addWidget(groupBox);
    00156
    00157         QValueList<KFileMetaInfoItem> readItems;
    00158         QValueList<KFileMetaInfoItem> editItems;
    00159
    00160         for (QStringList::Iterator iit = itemList.begin();
    00161                 iit!=itemList.end(); ++iit)
    00162         {
    00163             KFileMetaInfoItem item = d->m_info[*git][*iit];
    00164             if ( !item.isValid() ) continue;
    00165
    00166             bool editable = file_info.isWritable() && item.isEditable();
    00167
    00168             if (editable)
    00169                 editItems.append( item );
    00170             else
    00171                 readItems.append( item );
    00172         }
    00173
    00174         KFileMetaInfoWidget* w = 0L;
    00175         // then first add the editable items to the layout
    00176         for (QValueList<KFileMetaInfoItem>::Iterator iit= editItems.begin();
    00177                 iit!=editItems.end(); ++iit)
    00178         {
    00179             (new QLabel((*iit).translatedKey() + ":", groupBox));
    00180             QValidator* val = mtinfo->createValidator(*git, (*iit).key());
    00181             if (!val) kdDebug(7033) << "didn't get a validator for " << *git << "/" << (*iit).key() << endl;
    00182             w = new KFileMetaInfoWidget(*iit, val, groupBox);
    00183             d->m_editWidgets.append( w );
    00184             connect(w, SIGNAL(valueChanged(const QVariant&)), this, SIGNAL(changed()));
    00185         }
    00186
    00187         // and then the read only items
    00188         for (QValueList<KFileMetaInfoItem>::Iterator iit= readItems.begin();
    00189                 iit!=readItems.end(); ++iit)
    00190         {
    00191             (new QLabel((*iit).translatedKey() + ":", groupBox));
    00192             (new KFileMetaInfoWidget(*iit, 0L, groupBox));
    00193         }
    00194     }
    00195
    00196     toplayout->addStretch(1);
    00197
    00198     // the add key (disabled until fully implemented)
    00199 /*    d->m_add = new QPushButton(i18n("&Add"), topframe);
    00200     d->m_add->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
    00201                                         QSizePolicy::Fixed));
    00202     connect(d->m_add, SIGNAL(clicked()), this, SLOT(slotAdd()));
    00203     tmp->addWidget(d->m_add);
    00204
    00205     // if nothing can be added, deactivate it
    00206     if ( !d->m_info.supportsVariableKeys() )
    00207     {
    00208         // if supportedKeys() does contain anything not in preferredKeys,
    00209         // we have something addable
    00210
    00211         QStringList sk = d->m_info.supportedKeys();
    00212         d->m_add->setEnabled(false);
    00213         for (QStringList::Iterator it = sk.begin(); it!=sk.end(); ++it)
    00214         {
    00215                 if ( l.find(*it)==l.end() )
    00216                 {
    00217                     d->m_add->setEnabled(true);
    00218                     kdDebug(250) << "**first addable key is " << (*it).latin1() << "**" <<endl;
    00219                     break;
    00220                 }
    00221                 kdDebug(250) << "**already existing key is " << (*it).latin1() << "**" <<endl;
    00222         }
    00223     } */
    00224 }
    00225
    00226 /*void KFileMetaPropsPlugin::slotAdd()
    00227 {
    00228     // add a lineedit for the name
    00229
    00230
    00231
    00232     // insert the item in the list
    00233
    00234 }*/
    00235
    00236 KFileMetaPropsPlugin::~KFileMetaPropsPlugin()
    00237 {
    00238   delete d;
    00239 }
    00240
    00241 bool KFileMetaPropsPlugin::supports( KFileItemList _items )
    00242 {
    00243 #ifdef _GNUC
    00244 #warning TODO: Add support for more than one item
    00245 #endif
    00246   if (_items.count()!=1) return false;
    00247   return true;
    00248 }
    00249
    00250 void KFileMetaPropsPlugin::applyChanges()
    00251 {
    00252   kdDebug(250) << "applying changes" << endl;
    00253   // insert the fields that changed into the info object
    00254
    00255   QPtrListIterator<KFileMetaInfoWidget> it( d->m_editWidgets );
    00256   KFileMetaInfoWidget* w;
    00257   for (; (w = it.current()); ++it) w->apply();
    00258   d->m_info.applyChanges();
    00259 }
    00260
    00261 #include "kmetaprops.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:39 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001