kio Library: kmetaprops.cpp Source File (kio Library)

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

This file is part of the documentation for kio Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:23:59 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003