• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
tdefilelist.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "tdefilelist.h"
21 
22 #include <tqtoolbutton.h>
23 #include <tqlabel.h>
24 #include <tqlayout.h>
25 #include <tqtooltip.h>
26 #include <tqheader.h>
27 #include <tqwhatsthis.h>
28 
29 #include <tdeio/netaccess.h>
30 #include <kurldrag.h>
31 #include <tdefiledialog.h>
32 #include <tdelocale.h>
33 #include <kiconloader.h>
34 #include <tdelistview.h>
35 #include <krun.h>
36 #include <kmimetype.h>
37 
38 KFileList::KFileList(TQWidget *parent, const char *name)
39 : TQWidget(parent, name)
40 {
41  //WhatsThis strings.... (added by pfeifle@kde.org)
42  TQString whatsThisAddFileButton = i18n( " <qt> <b>Add File button</b>"
43  " <p>This button calls the <em>'File Open'</em> dialog to let you"
44  " select a file for printing. Note, that "
45  " <ul><li>you can select ASCII or International Text, PDF,"
46  " PostScript, JPEG, TIFF, PNG, GIF and many other graphic"
47  " formats."
48  " <li>you can select various files from different paths"
49  " and send them as one \"multi-file job\" to the printing"
50  " system."
51  " </ul>"
52  " </qt>" );
53 
54  TQString whatsThisRemoveFileButton = i18n(" <qt> <b>Remove File button</b>"
55  " <p>This button removes the highlighted file from the"
56  " list of to-be-printed files."
57  " </qt>" );
58 
59  TQString whatsThisMoveFileUpButton = i18n(" <qt> <b>Move File Up button</b>"
60  " <p>This button moves the highlighted file up in the list"
61  " of files to be printed.</p>"
62  " <p>In effect, this changes the order"
63  " of the files' printout.</p>"
64  " </qt>" );
65 
66  TQString whatsThisMoveFileDownButton = i18n(" <qt> <b>Move File Down button</b>"
67  " <p>This button moves the highlighted file down in the list"
68  " of files to be printed.</p>"
69  " <p>In effect, this changes the order"
70  " of the files' printout.</p>"
71  " </qt>" );
72 
73  TQString whatsThisOpenFileButton = i18n( " <qt> <b>File Open button</b>"
74  " <p>This button tries to open the highlighted file, so"
75  " you can view or edit it before you send it to the printing"
76  " system.</p>"
77  " <p>If you open"
78  " files, TDEPrint will use the application matching the MIME type of"
79  " the file.</p>"
80  " </qt>" );
81 
82  TQString whatsThisFileSelectionListview = i18n( " <qt> <b>File List view</b>"
83  " <p>This list displays all the files you selected for printing."
84  " You can see the file name(s), file path(s) and the file"
85  " (MIME) type(s) as determined by TDEPrint. You may re-arrange the "
86  " initial order of the list "
87  " with the help of the arrow buttons on the right.</p>"
88  " <p>The files will be printed as a single job,"
89  " in the same order as displayed in the list.</p>"
90  " <p><b>Note:</b> You can select multiple files. The files may be in multiple"
91  " locations. The files may be of multiple MIME types. The buttons on the right"
92  " side let you add more files, remove already selected files from the list, "
93  " re-order the list (by moving files up or down), and open files. If you open"
94  " files, TDEPrint will use the application matching the MIME type of"
95  " the file.</p>"
96  " </qt>" );
97 
98  m_block = false;
99 
100  m_files = new TDEListView(this);
101  m_files->addColumn(i18n("Name"));
102  m_files->addColumn(i18n("Type"));
103  m_files->addColumn(i18n("Path"));
104  m_files->setAllColumnsShowFocus(true);
105  m_files->setSorting(-1);
106  m_files->setAcceptDrops(false);
107  m_files->setSelectionMode(TQListView::Extended);
108  m_files->header()->setStretchEnabled(true, 2);
109  TQWhatsThis::add(m_files, whatsThisFileSelectionListview);
110  connect(m_files, TQ_SIGNAL(selectionChanged()), TQ_SLOT(slotSelectionChanged()));
111 
112  m_add = new TQToolButton(this);
113  m_add->setIconSet(SmallIconSet("document-open"));
114  connect(m_add, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddFile()));
115  TQToolTip::add(m_add, i18n("Add file"));
116  TQWhatsThis::add(m_add, whatsThisAddFileButton);
117 
118  m_remove = new TQToolButton(this);
119  m_remove->setIconSet(SmallIconSet("remove"));
120  connect(m_remove, TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveFile()));
121  TQToolTip::add(m_remove, i18n("Remove file"));
122  TQWhatsThis::add(m_remove, whatsThisRemoveFileButton);
123  m_remove->setEnabled(false);
124 
125  m_open = new TQToolButton(this);
126  m_open->setIconSet(SmallIconSet("filefind"));
127  connect(m_open, TQ_SIGNAL(clicked()), TQ_SLOT(slotOpenFile()));
128  TQToolTip::add(m_open, i18n("Open file"));
129  TQWhatsThis::add(m_open, whatsThisOpenFileButton);
130  m_open->setEnabled(false);
131 
132  m_up = new TQToolButton(this);
133  m_up->setIconSet(SmallIconSet("go-up"));
134  connect(m_up, TQ_SIGNAL(clicked()), TQ_SLOT(slotUp()));
135  TQToolTip::add(m_up, i18n("Move up"));
136  TQWhatsThis::add(m_up, whatsThisMoveFileUpButton);
137  m_up->setEnabled(false);
138 
139  m_down = new TQToolButton(this);
140  m_down->setIconSet(SmallIconSet("go-down"));
141  connect(m_down, TQ_SIGNAL(clicked()), TQ_SLOT(slotDown()));
142  TQToolTip::add(m_down, i18n("Move down"));
143  TQWhatsThis::add(m_down, whatsThisMoveFileDownButton);
144  m_down->setEnabled(false);
145 
146  setAcceptDrops(true);
147 
148  TQToolTip::add(m_files, i18n(
149  "Drag file(s) here or use the button to open a file dialog. "
150  "Leave empty for <b>&lt;STDIN&gt;</b>."));
151 
152  TQHBoxLayout *l0 = new TQHBoxLayout(this, 0, KDialog::spacingHint());
153  TQVBoxLayout *l1 = new TQVBoxLayout(0, 0, 1);
154  l0->addWidget(m_files);
155  l0->addLayout(l1);
156  l1->addWidget(m_add);
157  l1->addWidget(m_remove);
158  l1->addWidget(m_open);
159  l1->addSpacing(10);
160  l1->addWidget(m_up);
161  l1->addWidget(m_down);
162  l1->addStretch(1);
163 }
164 
165 KFileList::~KFileList()
166 {
167 }
168 
169 void KFileList::dragEnterEvent(TQDragEnterEvent *e)
170 {
171  e->accept(KURLDrag::canDecode(e));
172 }
173 
174 void KFileList::dropEvent(TQDropEvent *e)
175 {
176  KURL::List files;
177  if (KURLDrag::decode(e, files))
178  {
179  addFiles(files);
180  }
181 }
182 
183 void KFileList::addFiles(const KURL::List& files)
184 {
185  if (files.count() > 0)
186  {
187  // search last item in current list, to add new ones at the end
188  TQListViewItem *item = m_files->firstChild();
189  while (item && item->nextSibling())
190  item = item->nextSibling();
191 
192  for (KURL::List::ConstIterator it=files.begin(); it!=files.end(); ++it)
193  {
194  KMimeType::Ptr mime = KMimeType::findByURL( *it, 0, true, false);
195  item = new TQListViewItem(m_files, item, (*it).fileName(), mime->comment(), (*it).url());
196  item->setPixmap(0, mime->pixmap(*it, TDEIcon::Small));
197  }
198 
199  slotSelectionChanged();
200  /*
201  if (m_files->childCount() > 0)
202  {
203  m_remove->setEnabled(true);
204  m_open->setEnabled(true);
205  if (m_files->currentItem() == 0)
206  m_files->setSelected(m_files->firstChild(), true);
207  }
208  */
209  }
210 }
211 
212 void KFileList::setFileList(const TQStringList& files)
213 {
214  m_files->clear();
215  TQListViewItem *item = 0;
216  for (TQStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
217  {
218  KURL url = KURL::fromPathOrURL( *it );
219  KMimeType::Ptr mime = KMimeType::findByURL(url, 0, true, false);
220  item = new TQListViewItem(m_files, item, url.fileName(), mime->comment(), url.url());
221  item->setPixmap(0, mime->pixmap(url, TDEIcon::Small));
222  }
223  slotSelectionChanged();
224 }
225 
226 TQStringList KFileList::fileList() const
227 {
228  TQStringList l;
229  TQListViewItem *item = m_files->firstChild();
230  while (item)
231  {
232  l << item->text(2);
233  item = item->nextSibling();
234  }
235  return l;
236 }
237 
238 void KFileList::slotAddFile()
239 {
240  KURL::List fnames = KFileDialog::getOpenURLs(TQString::null, TQString::null, this);
241  if (!fnames.empty())
242  addFiles(fnames);
243 }
244 
245 void KFileList::slotRemoveFile()
246 {
247  TQPtrList<TQListViewItem> l;
248  selection(l);
249  l.setAutoDelete(true);
250  m_block = true;
251  l.clear();
252  m_block = false;
253  slotSelectionChanged();
254 }
255 
256 void KFileList::slotOpenFile()
257 {
258  TQListViewItem *item = m_files->currentItem();
259  if (item)
260  {
261  KURL url( item->text( 2 ) );
262  new KRun(url);
263  }
264 }
265 
266 TQSize KFileList::sizeHint() const
267 {
268  return TQSize(100, 100);
269 }
270 
271 void KFileList::selection(TQPtrList<TQListViewItem>& l)
272 {
273  l.setAutoDelete(false);
274  TQListViewItem *item = m_files->firstChild();
275  while (item)
276  {
277  if (item->isSelected())
278  l.append(item);
279  item = item->nextSibling();
280  }
281 }
282 
283 void KFileList::slotSelectionChanged()
284 {
285  if (m_block)
286  return;
287 
288  TQPtrList<TQListViewItem> l;
289  selection(l);
290  m_remove->setEnabled(l.count() > 0);
291  m_open->setEnabled(l.count() == 1);
292  m_up->setEnabled(l.count() == 1 && l.first()->itemAbove());
293  m_down->setEnabled(l.count() == 1 && l.first()->itemBelow());
294 }
295 
296 void KFileList::slotUp()
297 {
298  TQPtrList<TQListViewItem> l;
299  selection(l);
300  if (l.count() == 1 && l.first()->itemAbove())
301  {
302  TQListViewItem *item(l.first()), *clone;
303  clone = new TQListViewItem(m_files, item->itemAbove()->itemAbove(), item->text(0), item->text(1), item->text(2));
304  clone->setPixmap(0, *(item->pixmap(0)));
305  delete item;
306  m_files->setCurrentItem(clone);
307  m_files->setSelected(clone, true);
308  }
309 }
310 
311 void KFileList::slotDown()
312 {
313  TQPtrList<TQListViewItem> l;
314  selection(l);
315  if (l.count() == 1 && l.first()->itemBelow())
316  {
317  TQListViewItem *item(l.first()), *clone;
318  clone = new TQListViewItem(m_files, item->itemBelow(), item->text(0), item->text(1), item->text(2));
319  clone->setPixmap(0, *(item->pixmap(0)));
320  delete item;
321  m_files->setCurrentItem(clone);
322  m_files->setSelected(clone, true);
323  }
324 }
325 
326 #include "tdefilelist.moc"

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • 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 tdeprint by doxygen 1.9.1
This website is maintained by Timothy Pearson.