KIO
kmetaprops.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00073
00074
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
00090 if ( !d->m_info.isValid() )
00091 return;
00092
00093
00094
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
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
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
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
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 }
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 KFileMetaPropsPlugin::~KFileMetaPropsPlugin()
00206 {
00207 delete d;
00208 }
00209
00210 bool KFileMetaPropsPlugin::supports( const KFileItemList& _items )
00211 {
00212 kDebug() ;
00213
00214
00215
00216
00217
00218 if (KDesktopPropsPlugin::supports(_items) || KUrlPropsPlugin::supports(_items))
00219 return false;
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
00232
00233 foreach(KFileMetaInfoWidget* w, d->m_editWidgets)
00234 w->apply();
00235 d->m_info.applyChanges();
00236 }
00237
00238 #include "kmetaprops.moc"