• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
kmetaprops.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2001,2002 Rolf Magnus <ramagnus@kde.org>
3 
4  library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 
18  $Id$
19  */
20 
21 #include "kmetaprops.h"
22 
23 #include <kdebug.h>
24 #include <tdefilemetainfowidget.h>
25 #include <tdefilemetainfo.h>
26 #include <tdeglobal.h>
27 #include <tdeglobalsettings.h>
28 #include <tdelocale.h>
29 #include <kprotocolinfo.h>
30 
31 #include <tqvalidator.h>
32 #include <tqlayout.h>
33 #include <tqlabel.h>
34 #include <tqfileinfo.h>
35 #include <tqdatetime.h>
36 #include <tqstylesheet.h>
37 #include <tqvgroupbox.h>
38 
39 #undef Bool
40 
41 class MetaPropsScrollView : public TQScrollView
42 {
43 public:
44  MetaPropsScrollView(TQWidget* parent = 0, const char* name = 0)
45  : TQScrollView(parent, name)
46  {
47  setFrameStyle(TQFrame::NoFrame);
48  m_frame = new TQFrame(viewport(), "MetaPropsScrollView::m_frame");
49  m_frame->setFrameStyle(TQFrame::NoFrame);
50  addChild(m_frame, 0, 0);
51  };
52 
53  TQFrame* frame() {return m_frame;};
54 
55 protected:
56  virtual void viewportResizeEvent(TQResizeEvent* ev)
57  {
58  TQScrollView::viewportResizeEvent(ev);
59  m_frame->resize( kMax(m_frame->sizeHint().width(), ev->size().width()),
60  kMax(m_frame->sizeHint().height(), ev->size().height()));
61  };
62 
63 private:
64  TQFrame* m_frame;
65 };
66 
67 class KFileMetaPropsPlugin::KFileMetaPropsPluginPrivate
68 {
69 public:
70  KFileMetaPropsPluginPrivate() {}
71  ~KFileMetaPropsPluginPrivate() {}
72 
73  TQFrame* m_frame;
74  TQGridLayout* m_framelayout;
75  KFileMetaInfo m_info;
76 // TQPushButton* m_add;
77  TQPtrList<KFileMetaInfoWidget> m_editWidgets;
78 };
79 
80 KFileMetaPropsPlugin::KFileMetaPropsPlugin(KPropertiesDialog* props)
81  : KPropsDlgPlugin(props)
82 {
83  d = new KFileMetaPropsPluginPrivate;
84 
85  KFileItem * fileitem = properties->item();
86  kdDebug(250) << "KFileMetaPropsPlugin constructor" << endl;
87 
88  d->m_info = fileitem->metaInfo();
89  if (!d->m_info.isValid())
90  {
91  d->m_info = KFileMetaInfo(properties->kurl().path(-1));
92  fileitem->setMetaInfo(d->m_info);
93  }
94 
95  if ( properties->items().count() > 1 )
96  {
97  // not yet supported
98  // we should allow setting values for a list of files. Itt makes sense
99  // in some cases, like the album of a list of mp3s
100  return;
101  }
102 
103  createLayout();
104 
105  setDirty(true);
106 }
107 
108 void KFileMetaPropsPlugin::createLayout()
109 {
110  TQFileInfo file_info(properties->item()->url().path());
111 
112  kdDebug(250) << "KFileMetaPropsPlugin::createLayout" << endl;
113 
114  // is there any valid and non-empty info at all?
115  if ( !d->m_info.isValid() || (d->m_info.preferredKeys()).isEmpty() )
116  return;
117 
118  // now get a list of groups
119  KFileMetaInfoProvider* prov = KFileMetaInfoProvider::self();
120  TQStringList groupList = d->m_info.preferredGroups();
121 
122  const KFileMimeTypeInfo* mtinfo = prov->mimeTypeInfo(d->m_info.mimeType());
123  if (!mtinfo)
124  {
125  kdDebug(7034) << "no mimetype info there\n";
126  return;
127  }
128 
129  // let the dialog create the page frame
130  TQFrame* topframe = properties->addPage(i18n("&Meta Info"));
131  topframe->setFrameStyle(TQFrame::NoFrame);
132  TQVBoxLayout* tmp = new TQVBoxLayout(topframe);
133 
134  // create a scroll view in the page
135  MetaPropsScrollView* view = new MetaPropsScrollView(topframe);
136 
137  tmp->addWidget(view);
138 
139  d->m_frame = view->frame();
140 
141  TQVBoxLayout *toplayout = new TQVBoxLayout(d->m_frame);
142  toplayout->setSpacing(KDialog::spacingHint());
143 
144  for (TQStringList::Iterator git=groupList.begin();
145  git!=groupList.end(); ++git)
146  {
147  kdDebug(7033) << *git << endl;
148 
149  TQStringList itemList = d->m_info.group(*git).preferredKeys();
150  if (itemList.isEmpty())
151  continue;
152 
153  TQGroupBox *groupBox = new TQGroupBox(2, TQt::Horizontal,
154  TQStyleSheet::escape(mtinfo->groupInfo(*git)->translatedName()),
155  d->m_frame);
156 
157  toplayout->addWidget(groupBox);
158 
159  TQValueList<KFileMetaInfoItem> readItems;
160  TQValueList<KFileMetaInfoItem> editItems;
161 
162  for (TQStringList::Iterator iit = itemList.begin();
163  iit!=itemList.end(); ++iit)
164  {
165  KFileMetaInfoItem item = d->m_info[*git][*iit];
166  if ( !item.isValid() ) continue;
167 
168  bool editable = file_info.isWritable() && item.isEditable();
169 
170  if (editable)
171  editItems.append( item );
172  else
173  readItems.append( item );
174  }
175 
176  KFileMetaInfoWidget* w = 0L;
177  // then first add the editable items to the layout
178  for (TQValueList<KFileMetaInfoItem>::Iterator iit= editItems.begin();
179  iit!=editItems.end(); ++iit)
180  {
181  TQLabel* l = new TQLabel((*iit).translatedKey() + ":", groupBox);
182  l->setAlignment( AlignAuto | AlignTop | ExpandTabs );
183  TQValidator* val = mtinfo->createValidator(*git, (*iit).key());
184  if (!val) kdDebug(7033) << "didn't get a validator for " << *git << "/" << (*iit).key() << endl;
185  w = new KFileMetaInfoWidget(*iit, val, groupBox);
186  d->m_editWidgets.append( w );
187  connect(w, TQ_SIGNAL(valueChanged(const TQVariant&)), this, TQ_SIGNAL(changed()));
188  }
189 
190  // and then the read only items
191  for (TQValueList<KFileMetaInfoItem>::Iterator iit= readItems.begin();
192  iit!=readItems.end(); ++iit)
193  {
194  TQLabel* l = new TQLabel((*iit).translatedKey() + ":", groupBox);
195  l->setAlignment( AlignAuto | AlignTop | ExpandTabs );
196  (new KFileMetaInfoWidget(*iit, KFileMetaInfoWidget::ReadOnly, 0L, groupBox));
197  }
198  }
199 
200  toplayout->addStretch(1);
201 
202  // the add key (disabled until fully implemented)
203 /* d->m_add = new TQPushButton(i18n("&Add"), topframe);
204  d->m_add->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed,
205  TQSizePolicy::Fixed));
206  connect(d->m_add, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotAdd()));
207  tmp->addWidget(d->m_add);
208 
209  // if nothing can be added, deactivate it
210  if ( !d->m_info.supportsVariableKeys() )
211  {
212  // if supportedKeys() does contain anything not in preferredKeys,
213  // we have something addable
214 
215  TQStringList sk = d->m_info.supportedKeys();
216  d->m_add->setEnabled(false);
217  for (TQStringList::Iterator it = sk.begin(); it!=sk.end(); ++it)
218  {
219  if ( l.find(*it)==l.end() )
220  {
221  d->m_add->setEnabled(true);
222  kdDebug(250) << "**first addable key is " << (*it).latin1() << "**" <<endl;
223  break;
224  }
225  kdDebug(250) << "**already existing key is " << (*it).latin1() << "**" <<endl;
226  }
227  } */
228 }
229 
230 /*void KFileMetaPropsPlugin::slotAdd()
231 {
232  // add a lineedit for the name
233 
234 
235 
236  // insert the item in the list
237 
238 }*/
239 
240 KFileMetaPropsPlugin::~KFileMetaPropsPlugin()
241 {
242  delete d;
243 }
244 
245 bool KFileMetaPropsPlugin::supports( KFileItemList _items )
246 {
247 #ifdef _GNUC
248 #warning TODO: Add support for more than one item
249 #endif
250  if (KExecPropsPlugin::supports(_items) || KURLPropsPlugin::supports(_items))
251  return false; // Having both is redundant.
252 
253  bool metaDataEnabled = TDEGlobalSettings::showFilePreview(_items.first()->url());
254  return _items.count() == 1 && metaDataEnabled;
255 }
256 
257 void KFileMetaPropsPlugin::applyChanges()
258 {
259  kdDebug(250) << "applying changes" << endl;
260  // insert the fields that changed into the info object
261 
262  TQPtrListIterator<KFileMetaInfoWidget> it( d->m_editWidgets );
263  KFileMetaInfoWidget* w;
264  for (; (w = it.current()); ++it) w->apply();
265  d->m_info.applyChanges(properties->kurl().path());
266 }
267 
268 #include "kmetaprops.moc"
KFileMetaInfoWidget
Definition: tdefilemetainfowidget.h:31
KFileMetaPropsPlugin::supports
static bool supports(KFileItemList _items)
Tests whether the file specified by _items has a 'MetaInfo' plugin.
Definition: kmetaprops.cpp:245
KFileMetaPropsPlugin::KFileMetaPropsPlugin
KFileMetaPropsPlugin(KPropertiesDialog *_props)
Constructor.
Definition: kmetaprops.cpp:80
KFileMetaPropsPlugin::applyChanges
virtual void applyChanges()
Applies all changes to the file.
Definition: kmetaprops.cpp:257
KPropertiesDialog
The main properties dialog class.
Definition: kpropertiesdialog.h:71
KPropertiesDialog::items
KFileItemList items() const
Definition: kpropertiesdialog.h:267
KPropertiesDialog::kurl
const KURL & kurl() const
The URL of the file that has its properties being displayed.
Definition: kpropertiesdialog.h:253
KPropertiesDialog::item
KFileItem * item()
Definition: kpropertiesdialog.h:262
KPropsDlgPlugin
A Plugin in the Properties dialog This is an abstract class.
Definition: kpropertiesdialog.h:438
KPropsDlgPlugin::changed
void changed()
Emit this signal when the user changed anything in the plugin's tabs.
KPropsDlgPlugin::properties
KPropertiesDialog * properties
Pointer to the dialog.
Definition: kpropertiesdialog.h:480

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.9.1
This website is maintained by Timothy Pearson.