kmetaprops.cpp
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
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 
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         
00098         
00099         
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     
00115     if ( !d->m_info.isValid() || (d->m_info.preferredKeys()).isEmpty() )
00116         return;
00117 
00118     
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     
00130     QFrame* topframe = properties->addPage(i18n("&Meta Info"));
00131     topframe->setFrameStyle(QFrame::NoFrame);
00132     QVBoxLayout* tmp = new QVBoxLayout(topframe);
00133 
00134     
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         
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         
00190         for (QValueList<KFileMetaInfoItem>::Iterator iit= readItems.begin(); 
00191                 iit!=readItems.end(); ++iit)
00192         {
00193             (new QLabel((*iit).translatedKey() + ":", groupBox));
00194             (new KFileMetaInfoWidget(*iit, 0L, groupBox));
00195         }
00196     }
00197 
00198     toplayout->addStretch(1);
00199 
00200     
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 }
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
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))
00249      return false; 
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   
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.2.0.