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().path());
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 toplayout->setSpacing(KDialog::spacingHint());
00109
00110 foreach (const KFileMetaInfoGroup& group, groupList) {
00111
00112
00113 KFileMetaInfoItemList itemList = group.items();
00114 if (itemList.isEmpty())
00115 continue;
00116
00117 QGroupBox *groupBox = new QGroupBox( Qt::escape(group.name()),
00118 d->m_frame);
00119 QGridLayout *grouplayout = new QGridLayout(groupBox);
00120 grouplayout->activate();
00121
00122 toplayout->addWidget(groupBox);
00123
00124 KFileMetaInfoItemList readItems;
00125 KFileMetaInfoItemList editItems;
00126
00127 foreach (const KFileMetaInfoItem& item, itemList) {
00128 if ( !item.isValid() ) continue;
00129
00130 bool editable = file_info.isWritable() && item.isEditable();
00131
00132 if (editable)
00133 editItems.append( item );
00134 else
00135 readItems.append( item );
00136 }
00137
00138 KFileMetaInfoWidget* w = 0L;
00139 int row = 0;
00140
00141 foreach (const KFileMetaInfoItem& item, editItems) {
00142 QLabel* l = new QLabel(item.name() + ':', groupBox);
00143 grouplayout->addWidget(l, row, 0);
00144 l->setAlignment( Qt::AlignLeft | Qt::AlignTop );
00145 QValidator* val = item.properties().createValidator();
00146 if (!val) kDebug(7033) << "didn't get a validator for "
00147 << item.name() << endl;
00148 w = new KFileMetaInfoWidget(item, val, groupBox);
00149 grouplayout->addWidget(w, row, 1);
00150 d->m_editWidgets.append( w );
00151 connect(w, SIGNAL(valueChanged(const QVariant&)), this, SIGNAL(changed()));
00152 ++row;
00153 }
00154
00155
00156 foreach (const KFileMetaInfoItem& item, readItems) {
00157 QLabel* l = new QLabel(item.name() + ':', groupBox);
00158 grouplayout->addWidget(l, row, 0);
00159 l->setAlignment( Qt::AlignLeft | Qt::AlignTop );
00160 w = new KFileMetaInfoWidget(item, KFileMetaInfoWidget::ReadOnly, 0L, groupBox);
00161 grouplayout->addWidget(w, row, 1);
00162 ++row;
00163 }
00164 }
00165
00166 toplayout->addStretch(1);
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
00206 KFileMetaPropsPlugin::~KFileMetaPropsPlugin()
00207 {
00208 delete d;
00209 }
00210
00211 bool KFileMetaPropsPlugin::supports( const KFileItemList& _items )
00212 {
00213 kDebug() ;
00214
00215
00216
00217
00218
00219 if (KDesktopPropsPlugin::supports(_items) || KUrlPropsPlugin::supports(_items))
00220 return false;
00221 if (_items.count() != 1)
00222 return false;
00223
00224 bool metaDataEnabled = KGlobalSettings::showFilePreview(_items.first().url());
00225 kDebug() << "metaDataEnabled=" << metaDataEnabled;
00226 return metaDataEnabled;
00227 }
00228
00229 void KFileMetaPropsPlugin::applyChanges()
00230 {
00231 kDebug(250) << "applying changes";
00232
00233
00234 foreach(KFileMetaInfoWidget* w, d->m_editWidgets)
00235 w->apply();
00236 d->m_info.applyChanges();
00237 }
00238
00239 #include "kmetaprops.moc"