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.
327 lines
9.9 KiB
327 lines
9.9 KiB
15 years ago
|
/*
|
||
|
* This file is part of the KDE libraries
|
||
13 years ago
|
* Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
|
||
15 years ago
|
*
|
||
|
* This 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.
|
||
|
**/
|
||
|
|
||
12 years ago
|
#include "tdefilelist.h"
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqtoolbutton.h>
|
||
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqtooltip.h>
|
||
|
#include <tqheader.h>
|
||
|
#include <tqwhatsthis.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeio/netaccess.h>
|
||
15 years ago
|
#include <kurldrag.h>
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
15 years ago
|
#include <klocale.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <klistview.h>
|
||
|
#include <krun.h>
|
||
|
#include <kmimetype.h>
|
||
|
|
||
15 years ago
|
KFileList::KFileList(TQWidget *parent, const char *name)
|
||
|
: TQWidget(parent, name)
|
||
15 years ago
|
{
|
||
|
//WhatsThis strings.... (added by pfeifle@kde.org)
|
||
15 years ago
|
TQString whatsThisAddFileButton = i18n( " <qt> <b>Add File button</b>"
|
||
15 years ago
|
" <p>This button calls the <em>'File Open'</em> dialog to let you"
|
||
|
" select a file for printing. Note, that "
|
||
|
" <ul><li>you can select ASCII or International Text, PDF,"
|
||
|
" PostScript, JPEG, TIFF, PNG, GIF and many other graphic"
|
||
|
" formats."
|
||
|
" <li>you can select various files from different paths"
|
||
|
" and send them as one \"multi-file job\" to the printing"
|
||
|
" system."
|
||
|
" </ul>"
|
||
|
" </qt>" );
|
||
|
|
||
15 years ago
|
TQString whatsThisRemoveFileButton = i18n(" <qt> <b>Remove File button</b>"
|
||
15 years ago
|
" <p>This button removes the highlighted file from the"
|
||
|
" list of to-be-printed files."
|
||
|
" </qt>" );
|
||
|
|
||
15 years ago
|
TQString whatsThisMoveFileUpButton = i18n(" <qt> <b>Move File Up button</b>"
|
||
15 years ago
|
" <p>This button moves the highlighted file up in the list"
|
||
|
" of files to be printed.</p>"
|
||
|
" <p>In effect, this changes the order"
|
||
|
" of the files' printout.</p>"
|
||
|
" </qt>" );
|
||
|
|
||
15 years ago
|
TQString whatsThisMoveFileDownButton = i18n(" <qt> <b>Move File Down button</b>"
|
||
15 years ago
|
" <p>This button moves the highlighted file down in the list"
|
||
|
" of files to be printed.</p>"
|
||
|
" <p>In effect, this changes the order"
|
||
|
" of the files' printout.</p>"
|
||
|
" </qt>" );
|
||
|
|
||
15 years ago
|
TQString whatsThisOpenFileButton = i18n( " <qt> <b>File Open button</b>"
|
||
15 years ago
|
" <p>This button tries to open the highlighted file, so"
|
||
|
" you can view or edit it before you send it to the printing"
|
||
|
" system.</p>"
|
||
|
" <p>If you open"
|
||
13 years ago
|
" files, TDEPrint will use the application matching the MIME type of"
|
||
15 years ago
|
" the file.</p>"
|
||
|
" </qt>" );
|
||
|
|
||
15 years ago
|
TQString whatsThisFileSelectionListview = i18n( " <qt> <b>File List view</b>"
|
||
15 years ago
|
" <p>This list displays all the files you selected for printing."
|
||
|
" You can see the file name(s), file path(s) and the file"
|
||
13 years ago
|
" (MIME) type(s) as determined by TDEPrint. You may re-arrange the "
|
||
15 years ago
|
" initial order of the list "
|
||
|
" with the help of the arrow buttons on the right.</p>"
|
||
|
" <p>The files will be printed as a single job,"
|
||
|
" in the same order as displayed in the list.</p>"
|
||
|
" <p><b>Note:</b> You can select multiple files. The files may be in multiple"
|
||
|
" locations. The files may be of multiple MIME types. The buttons on the right"
|
||
|
" side let you add more files, remove already selected files from the list, "
|
||
|
" re-order the list (by moving files up or down), and open files. If you open"
|
||
13 years ago
|
" files, TDEPrint will use the application matching the MIME type of"
|
||
15 years ago
|
" the file.</p>"
|
||
|
" </qt>" );
|
||
|
|
||
|
m_block = false;
|
||
|
|
||
|
m_files = new KListView(this);
|
||
|
m_files->addColumn(i18n("Name"));
|
||
|
m_files->addColumn(i18n("Type"));
|
||
|
m_files->addColumn(i18n("Path"));
|
||
|
m_files->setAllColumnsShowFocus(true);
|
||
|
m_files->setSorting(-1);
|
||
|
m_files->setAcceptDrops(false);
|
||
15 years ago
|
m_files->setSelectionMode(TQListView::Extended);
|
||
15 years ago
|
m_files->header()->setStretchEnabled(true, 2);
|
||
15 years ago
|
TQWhatsThis::add(m_files, whatsThisFileSelectionListview);
|
||
|
connect(m_files, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelectionChanged()));
|
||
15 years ago
|
|
||
15 years ago
|
m_add = new TQToolButton(this);
|
||
15 years ago
|
m_add->setIconSet(SmallIconSet("fileopen"));
|
||
15 years ago
|
connect(m_add, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddFile()));
|
||
|
TQToolTip::add(m_add, i18n("Add file"));
|
||
|
TQWhatsThis::add(m_add, whatsThisAddFileButton);
|
||
15 years ago
|
|
||
15 years ago
|
m_remove = new TQToolButton(this);
|
||
15 years ago
|
m_remove->setIconSet(SmallIconSet("remove"));
|
||
15 years ago
|
connect(m_remove, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveFile()));
|
||
|
TQToolTip::add(m_remove, i18n("Remove file"));
|
||
|
TQWhatsThis::add(m_remove, whatsThisRemoveFileButton);
|
||
15 years ago
|
m_remove->setEnabled(false);
|
||
|
|
||
15 years ago
|
m_open = new TQToolButton(this);
|
||
14 years ago
|
m_open->setIconSet(SmallIconSet("filefind"));
|
||
15 years ago
|
connect(m_open, TQT_SIGNAL(clicked()), TQT_SLOT(slotOpenFile()));
|
||
|
TQToolTip::add(m_open, i18n("Open file"));
|
||
|
TQWhatsThis::add(m_open, whatsThisOpenFileButton);
|
||
15 years ago
|
m_open->setEnabled(false);
|
||
|
|
||
15 years ago
|
m_up = new TQToolButton(this);
|
||
15 years ago
|
m_up->setIconSet(SmallIconSet("up"));
|
||
15 years ago
|
connect(m_up, TQT_SIGNAL(clicked()), TQT_SLOT(slotUp()));
|
||
|
TQToolTip::add(m_up, i18n("Move up"));
|
||
|
TQWhatsThis::add(m_up, whatsThisMoveFileUpButton);
|
||
15 years ago
|
m_up->setEnabled(false);
|
||
|
|
||
15 years ago
|
m_down = new TQToolButton(this);
|
||
15 years ago
|
m_down->setIconSet(SmallIconSet("down"));
|
||
15 years ago
|
connect(m_down, TQT_SIGNAL(clicked()), TQT_SLOT(slotDown()));
|
||
|
TQToolTip::add(m_down, i18n("Move down"));
|
||
|
TQWhatsThis::add(m_down, whatsThisMoveFileDownButton);
|
||
15 years ago
|
m_down->setEnabled(false);
|
||
|
|
||
|
setAcceptDrops(true);
|
||
|
|
||
15 years ago
|
TQToolTip::add(m_files, i18n(
|
||
15 years ago
|
"Drag file(s) here or use the button to open a file dialog. "
|
||
|
"Leave empty for <b><STDIN></b>."));
|
||
|
|
||
14 years ago
|
TQHBoxLayout *l0 = new TQHBoxLayout(this, 0, KDialog::spacingHint());
|
||
|
TQVBoxLayout *l1 = new TQVBoxLayout(0, 0, 1);
|
||
15 years ago
|
l0->addWidget(m_files);
|
||
|
l0->addLayout(l1);
|
||
|
l1->addWidget(m_add);
|
||
|
l1->addWidget(m_remove);
|
||
|
l1->addWidget(m_open);
|
||
|
l1->addSpacing(10);
|
||
|
l1->addWidget(m_up);
|
||
|
l1->addWidget(m_down);
|
||
|
l1->addStretch(1);
|
||
|
}
|
||
|
|
||
|
KFileList::~KFileList()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void KFileList::dragEnterEvent(TQDragEnterEvent *e)
|
||
15 years ago
|
{
|
||
|
e->accept(KURLDrag::canDecode(e));
|
||
|
}
|
||
|
|
||
15 years ago
|
void KFileList::dropEvent(TQDropEvent *e)
|
||
15 years ago
|
{
|
||
|
KURL::List files;
|
||
|
if (KURLDrag::decode(e, files))
|
||
|
{
|
||
|
addFiles(files);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KFileList::addFiles(const KURL::List& files)
|
||
|
{
|
||
|
if (files.count() > 0)
|
||
|
{
|
||
|
// search last item in current list, to add new ones at the end
|
||
14 years ago
|
TQListViewItem *item = m_files->firstChild();
|
||
15 years ago
|
while (item && item->nextSibling())
|
||
|
item = item->nextSibling();
|
||
|
|
||
|
for (KURL::List::ConstIterator it=files.begin(); it!=files.end(); ++it)
|
||
|
{
|
||
|
KMimeType::Ptr mime = KMimeType::findByURL( *it, 0, true, false);
|
||
15 years ago
|
item = new TQListViewItem(m_files, item, (*it).fileName(), mime->comment(), (*it).url());
|
||
15 years ago
|
item->setPixmap(0, mime->pixmap(*it, KIcon::Small));
|
||
|
}
|
||
|
|
||
|
slotSelectionChanged();
|
||
|
/*
|
||
|
if (m_files->childCount() > 0)
|
||
|
{
|
||
|
m_remove->setEnabled(true);
|
||
|
m_open->setEnabled(true);
|
||
|
if (m_files->currentItem() == 0)
|
||
|
m_files->setSelected(m_files->firstChild(), true);
|
||
|
}
|
||
|
*/
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KFileList::setFileList(const TQStringList& files)
|
||
15 years ago
|
{
|
||
|
m_files->clear();
|
||
15 years ago
|
TQListViewItem *item = 0;
|
||
|
for (TQStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
|
||
15 years ago
|
{
|
||
|
KURL url = KURL::fromPathOrURL( *it );
|
||
|
KMimeType::Ptr mime = KMimeType::findByURL(url, 0, true, false);
|
||
15 years ago
|
item = new TQListViewItem(m_files, item, url.fileName(), mime->comment(), url.url());
|
||
15 years ago
|
item->setPixmap(0, mime->pixmap(url, KIcon::Small));
|
||
|
}
|
||
|
slotSelectionChanged();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList KFileList::fileList() const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQStringList l;
|
||
|
TQListViewItem *item = m_files->firstChild();
|
||
15 years ago
|
while (item)
|
||
|
{
|
||
|
l << item->text(2);
|
||
|
item = item->nextSibling();
|
||
|
}
|
||
|
return l;
|
||
|
}
|
||
|
|
||
|
void KFileList::slotAddFile()
|
||
|
{
|
||
15 years ago
|
KURL::List fnames = KFileDialog::getOpenURLs(TQString::null, TQString::null, this);
|
||
15 years ago
|
if (!fnames.empty())
|
||
|
addFiles(fnames);
|
||
|
}
|
||
|
|
||
|
void KFileList::slotRemoveFile()
|
||
|
{
|
||
15 years ago
|
TQPtrList<TQListViewItem> l;
|
||
15 years ago
|
selection(l);
|
||
|
l.setAutoDelete(true);
|
||
|
m_block = true;
|
||
|
l.clear();
|
||
|
m_block = false;
|
||
|
slotSelectionChanged();
|
||
|
}
|
||
|
|
||
|
void KFileList::slotOpenFile()
|
||
|
{
|
||
14 years ago
|
TQListViewItem *item = m_files->currentItem();
|
||
15 years ago
|
if (item)
|
||
|
{
|
||
|
KURL url( item->text( 2 ) );
|
||
|
new KRun(url);
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
TQSize KFileList::sizeHint() const
|
||
15 years ago
|
{
|
||
15 years ago
|
return TQSize(100, 100);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KFileList::selection(TQPtrList<TQListViewItem>& l)
|
||
15 years ago
|
{
|
||
|
l.setAutoDelete(false);
|
||
14 years ago
|
TQListViewItem *item = m_files->firstChild();
|
||
15 years ago
|
while (item)
|
||
|
{
|
||
|
if (item->isSelected())
|
||
|
l.append(item);
|
||
|
item = item->nextSibling();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KFileList::slotSelectionChanged()
|
||
|
{
|
||
|
if (m_block)
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQPtrList<TQListViewItem> l;
|
||
15 years ago
|
selection(l);
|
||
|
m_remove->setEnabled(l.count() > 0);
|
||
|
m_open->setEnabled(l.count() == 1);
|
||
|
m_up->setEnabled(l.count() == 1 && l.first()->itemAbove());
|
||
|
m_down->setEnabled(l.count() == 1 && l.first()->itemBelow());
|
||
|
}
|
||
|
|
||
|
void KFileList::slotUp()
|
||
|
{
|
||
15 years ago
|
TQPtrList<TQListViewItem> l;
|
||
15 years ago
|
selection(l);
|
||
|
if (l.count() == 1 && l.first()->itemAbove())
|
||
|
{
|
||
14 years ago
|
TQListViewItem *item(l.first()), *clone;
|
||
15 years ago
|
clone = new TQListViewItem(m_files, item->itemAbove()->itemAbove(), item->text(0), item->text(1), item->text(2));
|
||
15 years ago
|
clone->setPixmap(0, *(item->pixmap(0)));
|
||
|
delete item;
|
||
|
m_files->setCurrentItem(clone);
|
||
|
m_files->setSelected(clone, true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KFileList::slotDown()
|
||
|
{
|
||
15 years ago
|
TQPtrList<TQListViewItem> l;
|
||
15 years ago
|
selection(l);
|
||
|
if (l.count() == 1 && l.first()->itemBelow())
|
||
|
{
|
||
14 years ago
|
TQListViewItem *item(l.first()), *clone;
|
||
15 years ago
|
clone = new TQListViewItem(m_files, item->itemBelow(), item->text(0), item->text(1), item->text(2));
|
||
15 years ago
|
clone->setPixmap(0, *(item->pixmap(0)));
|
||
|
delete item;
|
||
|
m_files->setCurrentItem(clone);
|
||
|
m_files->setSelected(clone, true);
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdefilelist.moc"
|