You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
269 lines
8.3 KiB
269 lines
8.3 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2001,2002 Rolf Magnus <ramagnus@kde.org>
|
||
|
|
||
|
library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
|
||
|
$Id$
|
||
|
*/
|
||
|
|
||
|
#include "kmetaprops.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdefilemetainfowidget.h>
|
||
|
#include <tdefilemetainfo.h>
|
||
15 years ago
|
#include <kglobal.h>
|
||
|
#include <kglobalsettings.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kprotocolinfo.h>
|
||
|
|
||
15 years ago
|
#include <tqvalidator.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqfileinfo.h>
|
||
|
#include <tqdatetime.h>
|
||
13 years ago
|
#include <tqstylesheet.h>
|
||
15 years ago
|
#include <tqvgroupbox.h>
|
||
15 years ago
|
|
||
|
#undef Bool
|
||
|
|
||
14 years ago
|
class MetaPropsScrollView : public TQScrollView
|
||
15 years ago
|
{
|
||
|
public:
|
||
15 years ago
|
MetaPropsScrollView(TQWidget* parent = 0, const char* name = 0)
|
||
|
: TQScrollView(parent, name)
|
||
15 years ago
|
{
|
||
15 years ago
|
setFrameStyle(TQFrame::NoFrame);
|
||
|
m_frame = new TQFrame(viewport(), "MetaPropsScrollView::m_frame");
|
||
|
m_frame->setFrameStyle(TQFrame::NoFrame);
|
||
15 years ago
|
addChild(m_frame, 0, 0);
|
||
|
};
|
||
|
|
||
15 years ago
|
TQFrame* frame() {return m_frame;};
|
||
15 years ago
|
|
||
|
protected:
|
||
15 years ago
|
virtual void viewportResizeEvent(TQResizeEvent* ev)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQScrollView::viewportResizeEvent(ev);
|
||
13 years ago
|
m_frame->resize( kMax(m_frame->sizeHint().width(), ev->size().width()),
|
||
|
kMax(m_frame->sizeHint().height(), ev->size().height()));
|
||
15 years ago
|
};
|
||
|
|
||
|
private:
|
||
15 years ago
|
TQFrame* m_frame;
|
||
15 years ago
|
};
|
||
|
|
||
|
class KFileMetaPropsPlugin::KFileMetaPropsPluginPrivate
|
||
|
{
|
||
|
public:
|
||
|
KFileMetaPropsPluginPrivate() {}
|
||
|
~KFileMetaPropsPluginPrivate() {}
|
||
|
|
||
15 years ago
|
TQFrame* m_frame;
|
||
14 years ago
|
TQGridLayout* m_framelayout;
|
||
15 years ago
|
KFileMetaInfo m_info;
|
||
15 years ago
|
// TQPushButton* m_add;
|
||
|
TQPtrList<KFileMetaInfoWidget> m_editWidgets;
|
||
15 years ago
|
};
|
||
|
|
||
|
KFileMetaPropsPlugin::KFileMetaPropsPlugin(KPropertiesDialog* props)
|
||
|
: KPropsDlgPlugin(props)
|
||
|
{
|
||
|
d = new KFileMetaPropsPluginPrivate;
|
||
|
|
||
|
KFileItem * fileitem = properties->item();
|
||
|
kdDebug(250) << "KFileMetaPropsPlugin constructor" << endl;
|
||
|
|
||
|
d->m_info = fileitem->metaInfo();
|
||
|
if (!d->m_info.isValid())
|
||
|
{
|
||
|
d->m_info = KFileMetaInfo(properties->kurl().path(-1));
|
||
|
fileitem->setMetaInfo(d->m_info);
|
||
|
}
|
||
|
|
||
|
if ( properties->items().count() > 1 )
|
||
|
{
|
||
|
// not yet supported
|
||
|
// we should allow setting values for a list of files. Itt makes sense
|
||
|
// in some cases, like the album of a list of mp3s
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
createLayout();
|
||
|
|
||
|
setDirty(true);
|
||
|
}
|
||
|
|
||
|
void KFileMetaPropsPlugin::createLayout()
|
||
|
{
|
||
15 years ago
|
TQFileInfo file_info(properties->item()->url().path());
|
||
15 years ago
|
|
||
|
kdDebug(250) << "KFileMetaPropsPlugin::createLayout" << endl;
|
||
|
|
||
|
// is there any valid and non-empty info at all?
|
||
|
if ( !d->m_info.isValid() || (d->m_info.preferredKeys()).isEmpty() )
|
||
|
return;
|
||
|
|
||
|
// now get a list of groups
|
||
|
KFileMetaInfoProvider* prov = KFileMetaInfoProvider::self();
|
||
15 years ago
|
TQStringList groupList = d->m_info.preferredGroups();
|
||
15 years ago
|
|
||
|
const KFileMimeTypeInfo* mtinfo = prov->mimeTypeInfo(d->m_info.mimeType());
|
||
|
if (!mtinfo)
|
||
|
{
|
||
|
kdDebug(7034) << "no mimetype info there\n";
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// let the dialog create the page frame
|
||
15 years ago
|
TQFrame* topframe = properties->addPage(i18n("&Meta Info"));
|
||
|
topframe->setFrameStyle(TQFrame::NoFrame);
|
||
|
TQVBoxLayout* tmp = new TQVBoxLayout(topframe);
|
||
15 years ago
|
|
||
|
// create a scroll view in the page
|
||
|
MetaPropsScrollView* view = new MetaPropsScrollView(topframe);
|
||
|
|
||
|
tmp->addWidget(view);
|
||
|
|
||
|
d->m_frame = view->frame();
|
||
|
|
||
14 years ago
|
TQVBoxLayout *toplayout = new TQVBoxLayout(d->m_frame);
|
||
|
toplayout->setSpacing(KDialog::spacingHint());
|
||
15 years ago
|
|
||
15 years ago
|
for (TQStringList::Iterator git=groupList.begin();
|
||
15 years ago
|
git!=groupList.end(); ++git)
|
||
|
{
|
||
|
kdDebug(7033) << *git << endl;
|
||
|
|
||
15 years ago
|
TQStringList itemList = d->m_info.group(*git).preferredKeys();
|
||
15 years ago
|
if (itemList.isEmpty())
|
||
|
continue;
|
||
|
|
||
15 years ago
|
TQGroupBox *groupBox = new TQGroupBox(2, Qt::Horizontal,
|
||
|
TQStyleSheet::escape(mtinfo->groupInfo(*git)->translatedName()),
|
||
15 years ago
|
d->m_frame);
|
||
|
|
||
14 years ago
|
toplayout->addWidget(groupBox);
|
||
15 years ago
|
|
||
15 years ago
|
TQValueList<KFileMetaInfoItem> readItems;
|
||
|
TQValueList<KFileMetaInfoItem> editItems;
|
||
15 years ago
|
|
||
15 years ago
|
for (TQStringList::Iterator iit = itemList.begin();
|
||
15 years ago
|
iit!=itemList.end(); ++iit)
|
||
|
{
|
||
|
KFileMetaInfoItem item = d->m_info[*git][*iit];
|
||
|
if ( !item.isValid() ) continue;
|
||
|
|
||
|
bool editable = file_info.isWritable() && item.isEditable();
|
||
|
|
||
|
if (editable)
|
||
|
editItems.append( item );
|
||
|
else
|
||
|
readItems.append( item );
|
||
|
}
|
||
|
|
||
|
KFileMetaInfoWidget* w = 0L;
|
||
14 years ago
|
// then first add the editable items to the layout
|
||
15 years ago
|
for (TQValueList<KFileMetaInfoItem>::Iterator iit= editItems.begin();
|
||
15 years ago
|
iit!=editItems.end(); ++iit)
|
||
|
{
|
||
15 years ago
|
TQLabel* l = new TQLabel((*iit).translatedKey() + ":", groupBox);
|
||
13 years ago
|
l->setAlignment( AlignAuto | AlignTop | ExpandTabs );
|
||
15 years ago
|
TQValidator* val = mtinfo->createValidator(*git, (*iit).key());
|
||
15 years ago
|
if (!val) kdDebug(7033) << "didn't get a validator for " << *git << "/" << (*iit).key() << endl;
|
||
|
w = new KFileMetaInfoWidget(*iit, val, groupBox);
|
||
|
d->m_editWidgets.append( w );
|
||
15 years ago
|
connect(w, TQT_SIGNAL(valueChanged(const TQVariant&)), this, TQT_SIGNAL(changed()));
|
||
15 years ago
|
}
|
||
|
|
||
|
// and then the read only items
|
||
15 years ago
|
for (TQValueList<KFileMetaInfoItem>::Iterator iit= readItems.begin();
|
||
15 years ago
|
iit!=readItems.end(); ++iit)
|
||
|
{
|
||
15 years ago
|
TQLabel* l = new TQLabel((*iit).translatedKey() + ":", groupBox);
|
||
13 years ago
|
l->setAlignment( AlignAuto | AlignTop | ExpandTabs );
|
||
15 years ago
|
(new KFileMetaInfoWidget(*iit, KFileMetaInfoWidget::ReadOnly, 0L, groupBox));
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
toplayout->addStretch(1);
|
||
15 years ago
|
|
||
|
// the add key (disabled until fully implemented)
|
||
15 years ago
|
/* d->m_add = new TQPushButton(i18n("&Add"), topframe);
|
||
13 years ago
|
d->m_add->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed,
|
||
15 years ago
|
TQSizePolicy::Fixed));
|
||
|
connect(d->m_add, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotAdd()));
|
||
15 years ago
|
tmp->addWidget(d->m_add);
|
||
|
|
||
|
// if nothing can be added, deactivate it
|
||
|
if ( !d->m_info.supportsVariableKeys() )
|
||
|
{
|
||
|
// if supportedKeys() does contain anything not in preferredKeys,
|
||
|
// we have something addable
|
||
|
|
||
15 years ago
|
TQStringList sk = d->m_info.supportedKeys();
|
||
15 years ago
|
d->m_add->setEnabled(false);
|
||
15 years ago
|
for (TQStringList::Iterator it = sk.begin(); it!=sk.end(); ++it)
|
||
15 years ago
|
{
|
||
13 years ago
|
if ( l.find(*it)==l.end() )
|
||
15 years ago
|
{
|
||
|
d->m_add->setEnabled(true);
|
||
|
kdDebug(250) << "**first addable key is " << (*it).latin1() << "**" <<endl;
|
||
|
break;
|
||
|
}
|
||
|
kdDebug(250) << "**already existing key is " << (*it).latin1() << "**" <<endl;
|
||
|
}
|
||
|
} */
|
||
|
}
|
||
|
|
||
|
/*void KFileMetaPropsPlugin::slotAdd()
|
||
|
{
|
||
|
// add a lineedit for the name
|
||
|
|
||
|
|
||
|
|
||
|
// insert the item in the list
|
||
|
|
||
|
}*/
|
||
|
|
||
|
KFileMetaPropsPlugin::~KFileMetaPropsPlugin()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
bool KFileMetaPropsPlugin::supports( KFileItemList _items )
|
||
|
{
|
||
|
#ifdef _GNUC
|
||
|
#warning TODO: Add support for more than one item
|
||
|
#endif
|
||
|
if (KExecPropsPlugin::supports(_items) || KURLPropsPlugin::supports(_items))
|
||
|
return false; // Having both is redundant.
|
||
|
|
||
12 years ago
|
bool metaDataEnabled = TDEGlobalSettings::showFilePreview(_items.first()->url());
|
||
15 years ago
|
return _items.count() == 1 && metaDataEnabled;
|
||
|
}
|
||
|
|
||
|
void KFileMetaPropsPlugin::applyChanges()
|
||
|
{
|
||
|
kdDebug(250) << "applying changes" << endl;
|
||
|
// insert the fields that changed into the info object
|
||
|
|
||
15 years ago
|
TQPtrListIterator<KFileMetaInfoWidget> it( d->m_editWidgets );
|
||
15 years ago
|
KFileMetaInfoWidget* w;
|
||
|
for (; (w = it.current()); ++it) w->apply();
|
||
|
d->m_info.applyChanges(properties->kurl().path());
|
||
|
}
|
||
|
|
||
|
#include "kmetaprops.moc"
|