20 #include "tdefilelist.h"
22 #include <tqtoolbutton.h>
25 #include <tqtooltip.h>
27 #include <tqwhatsthis.h>
29 #include <tdeio/netaccess.h>
31 #include <tdefiledialog.h>
32 #include <tdelocale.h>
33 #include <kiconloader.h>
34 #include <tdelistview.h>
36 #include <kmimetype.h>
38 KFileList::KFileList(TQWidget *parent,
const char *name)
39 : TQWidget(parent, name)
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"
48 " <li>you can select various files from different paths"
49 " and send them as one \"multi-file job\" to the printing"
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."
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>"
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>"
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"
78 " files, TDEPrint will use the application matching the MIME type of"
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"
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()));
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);
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);
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);
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);
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);
146 setAcceptDrops(
true);
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><STDIN></b>."));
152 TQHBoxLayout *l0 =
new TQHBoxLayout(
this, 0, KDialog::spacingHint());
153 TQVBoxLayout *l1 =
new TQVBoxLayout(0, 0, 1);
154 l0->addWidget(m_files);
156 l1->addWidget(m_add);
157 l1->addWidget(m_remove);
158 l1->addWidget(m_open);
161 l1->addWidget(m_down);
165 KFileList::~KFileList()
169 void KFileList::dragEnterEvent(TQDragEnterEvent *e)
171 e->accept(KURLDrag::canDecode(e));
174 void KFileList::dropEvent(TQDropEvent *e)
177 if (KURLDrag::decode(e, files))
183 void KFileList::addFiles(
const KURL::List& files)
185 if (files.count() > 0)
188 TQListViewItem *item = m_files->firstChild();
189 while (item && item->nextSibling())
190 item = item->nextSibling();
192 for (KURL::List::ConstIterator it=files.begin(); it!=files.end(); ++it)
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));
199 slotSelectionChanged();
212 void KFileList::setFileList(
const TQStringList& files)
215 TQListViewItem *item = 0;
216 for (TQStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
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));
223 slotSelectionChanged();
226 TQStringList KFileList::fileList()
const
229 TQListViewItem *item = m_files->firstChild();
233 item = item->nextSibling();
238 void KFileList::slotAddFile()
240 KURL::List fnames = KFileDialog::getOpenURLs(TQString::null, TQString::null,
this);
245 void KFileList::slotRemoveFile()
247 TQPtrList<TQListViewItem> l;
249 l.setAutoDelete(
true);
253 slotSelectionChanged();
256 void KFileList::slotOpenFile()
258 TQListViewItem *item = m_files->currentItem();
261 KURL url( item->text( 2 ) );
266 TQSize KFileList::sizeHint()
const
268 return TQSize(100, 100);
271 void KFileList::selection(TQPtrList<TQListViewItem>& l)
273 l.setAutoDelete(
false);
274 TQListViewItem *item = m_files->firstChild();
277 if (item->isSelected())
279 item = item->nextSibling();
283 void KFileList::slotSelectionChanged()
288 TQPtrList<TQListViewItem> 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());
296 void KFileList::slotUp()
298 TQPtrList<TQListViewItem> l;
300 if (l.count() == 1 && l.first()->itemAbove())
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)));
306 m_files->setCurrentItem(clone);
307 m_files->setSelected(clone,
true);
311 void KFileList::slotDown()
313 TQPtrList<TQListViewItem> l;
315 if (l.count() == 1 && l.first()->itemBelow())
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)));
321 m_files->setCurrentItem(clone);
322 m_files->setSelected(clone,
true);
326 #include "tdefilelist.moc"