From 903aacf3fda692b6fa7e7934ea158653b99cc6a5 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 1 Feb 2013 17:25:43 -0600 Subject: Fix FTBFS --- .../advanced/kcm_sambaconf/qmultichecklistitem.cpp | 159 -- .../advanced/kcm_sambaconf/qmultichecklistitem.h | 65 - .../kcm_sambaconf/qmultichectdelistitem.cpp | 159 ++ .../advanced/kcm_sambaconf/qmultichectdelistitem.h | 65 + kget/kmainwidget.cpp | 2548 -------------------- kget/kmainwidget.h | 233 -- kget/tdemainwidget.cpp | 2548 ++++++++++++++++++++ kget/tdemainwidget.h | 233 ++ kopete/libkopete/kopeteblacklister.cpp | 109 - kopete/libkopete/kopeteblacklister.h | 125 - kopete/libkopete/kopeteblactdelister.cpp | 109 + kopete/libkopete/kopeteblactdelister.h | 125 + kopete/libkopete/ui/addressbookselectordialog.cpp | 89 - kopete/libkopete/ui/addressbookselectordialog.h | 91 - kopete/libkopete/ui/addressbookselectorwidget.cpp | 171 -- kopete/libkopete/ui/addressbookselectorwidget.h | 91 - .../libkopete/ui/addressbookselectorwidget_base.ui | 175 -- .../libkopete/ui/addressbootdeselectordialog.cpp | 89 + kopete/libkopete/ui/addressbootdeselectordialog.h | 91 + .../libkopete/ui/addressbootdeselectorwidget.cpp | 171 ++ kopete/libkopete/ui/addressbootdeselectorwidget.h | 91 + .../ui/addressbootdeselectorwidget_base.ui | 175 ++ ksirc/test/nicklist.pl | 77 - ksirc/test/nictdelist.pl | 77 + 24 files changed, 3933 insertions(+), 3933 deletions(-) delete mode 100644 filesharing/advanced/kcm_sambaconf/qmultichecklistitem.cpp delete mode 100644 filesharing/advanced/kcm_sambaconf/qmultichecklistitem.h create mode 100644 filesharing/advanced/kcm_sambaconf/qmultichectdelistitem.cpp create mode 100644 filesharing/advanced/kcm_sambaconf/qmultichectdelistitem.h delete mode 100644 kget/kmainwidget.cpp delete mode 100644 kget/kmainwidget.h create mode 100644 kget/tdemainwidget.cpp create mode 100644 kget/tdemainwidget.h delete mode 100644 kopete/libkopete/kopeteblacklister.cpp delete mode 100644 kopete/libkopete/kopeteblacklister.h create mode 100644 kopete/libkopete/kopeteblactdelister.cpp create mode 100644 kopete/libkopete/kopeteblactdelister.h delete mode 100644 kopete/libkopete/ui/addressbookselectordialog.cpp delete mode 100644 kopete/libkopete/ui/addressbookselectordialog.h delete mode 100644 kopete/libkopete/ui/addressbookselectorwidget.cpp delete mode 100644 kopete/libkopete/ui/addressbookselectorwidget.h delete mode 100644 kopete/libkopete/ui/addressbookselectorwidget_base.ui create mode 100644 kopete/libkopete/ui/addressbootdeselectordialog.cpp create mode 100644 kopete/libkopete/ui/addressbootdeselectordialog.h create mode 100644 kopete/libkopete/ui/addressbootdeselectorwidget.cpp create mode 100644 kopete/libkopete/ui/addressbootdeselectorwidget.h create mode 100644 kopete/libkopete/ui/addressbootdeselectorwidget_base.ui delete mode 100644 ksirc/test/nicklist.pl create mode 100644 ksirc/test/nictdelist.pl diff --git a/filesharing/advanced/kcm_sambaconf/qmultichecklistitem.cpp b/filesharing/advanced/kcm_sambaconf/qmultichecklistitem.cpp deleted file mode 100644 index 187289b6..00000000 --- a/filesharing/advanced/kcm_sambaconf/qmultichecklistitem.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/*************************************************************************** - qmultichecklistitem.cpp - description - ------------------- - begin : Sun Jan 26 2003 - copyright : (C) 2003 by Jan Sch�fer - email : janschaefer@users.sourceforge.net - ***************************************************************************/ - -/****************************************************************************** - * * - * This file is part of KSambaPlugin. * - * * - * KSambaPlugin is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * KSambaPlugin 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with KSambaPlugin; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * * - ******************************************************************************/ - -#include -#include -#include -#include - -#include -#include - -#include "qmultichecklistitem.moc" -#include "qmultichecklistitem.h" - -static const int BoxSize = 16; - - -QMultiCheckListItem::QMultiCheckListItem( TQListView *parent=0) : - TQListViewItem(parent) { -} - -void QMultiCheckListItem::setOn(int column, bool b) { - if (column >= (int) checkBoxColumns.size()) { - checkBoxColumns.resize(column*2); - checkStates.resize(column*2); - } - - checkStates.setBit(column,b); - checkBoxColumns.setBit(column); - kdDebug(5009) << "setOn : " << column << endl; - repaint(); -} - -bool QMultiCheckListItem::isOn(int column) { - return checkStates.testBit(column); -} - -bool QMultiCheckListItem::isDisabled(int column) { - return disableStates.testBit(column); -} - -void QMultiCheckListItem::toggle(int column) { - if (column >= (int) checkBoxColumns.size()) { - checkBoxColumns.resize(column*2); - checkStates.resize(column*2); - } - - checkBoxColumns.setBit(column); - checkStates.toggleBit(column); - emit stateChanged(column,checkStates.testBit(column)); - - repaint(); -} - -void QMultiCheckListItem::setDisabled(int column, bool b) { - if (column >= (int) disableStates.size()) { - disableStates.resize(column*2); - } - - disableStates.setBit(column,b); -// KMessageBox::information(0L,TQString("setDisabled"),TQString("disable %1 ").arg(column)); - repaint(); -} - -void QMultiCheckListItem::paintCell(TQPainter *p,const TQColorGroup & cg, int col, int width, int align) -{ - - if ( !p ) - return; - - TQListView *lv = listView(); - if ( !lv ) - return; - - TQListViewItem::paintCell(p,cg,col,width,align ); - - int marg = lv->itemMargin(); -// int width = BoxSize + marg*2; - // use a provate color group and set the text/highlighted text colors - TQColorGroup mcg = cg; - - if (checkBoxColumns.testBit(col)) { - // Bold/Italic/use default checkboxes - // code allmost identical to TQCheckListItem - Q_ASSERT( lv ); //### - // I use the text color of defaultStyles[0], normalcol in parent listview -// mcg.setColor( TQColorGroup::Text, ((StyleListView*)lv)->normalcol ); - int x = 0; - if ( align == AlignCenter ) { - TQFontMetrics fm( lv->font() ); - x = (width - BoxSize - fm.width(text(0)))/2; - } - int y = (height() - BoxSize) / 2; - - if ( !isEnabled() || disableStates.testBit(col)) - p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) ); - else - p->setPen( TQPen( mcg.text(), 2 ) ); - - if ( isSelected() && lv->header()->mapToSection( 0 ) != 0 ) { - p->fillRect( 0, 0, x + marg + BoxSize + 4, height(), - mcg.brush( TQColorGroup::Highlight ) ); - if ( isEnabled() ) - p->setPen( TQPen( mcg.highlightedText(), 2 ) ); // FIXME! - use defaultstyles[0].selecol. luckily not used :) - } - p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); - x++; - y++; - if ( checkStates.testBit(col) ) { - TQPointArray a( 7*2 ); - int i, xx, yy; - xx = x+1+marg; - yy = y+5; - for ( i=0; i<3; i++ ) { - a.setPoint( 2*i, xx, yy ); - a.setPoint( 2*i+1, xx, yy+2 ); - xx++; yy++; - } - yy -= 2; - for ( i=3; i<7; i++ ) { - a.setPoint( 2*i, xx, yy ); - a.setPoint( 2*i+1, xx, yy+2 ); - xx++; yy--; - } - p->drawLineSegments( a ); - } - - } - - -} - - - diff --git a/filesharing/advanced/kcm_sambaconf/qmultichecklistitem.h b/filesharing/advanced/kcm_sambaconf/qmultichecklistitem.h deleted file mode 100644 index b378e228..00000000 --- a/filesharing/advanced/kcm_sambaconf/qmultichecklistitem.h +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************** - qextendedchecklistitem.h - description - ------------------- - begin : Sun Jan 26 2003 - copyright : (C) 2003 by Jan Sch�fer - email : janschaefer@users.sourceforge.net - ***************************************************************************/ - -/****************************************************************************** - * * - * This file is part of KSambaPlugin. * - * * - * KSambaPlugin is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * KSambaPlugin 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with KSambaPlugin; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * * - ******************************************************************************/ - -#ifndef _TQMULTICHECKLISTITEM_H_ -#define _TQMULTICHECKLISTITEM_H_ - -#include - -#include - -class QMultiCheckListItem : public TQObject, public TQListViewItem { -Q_OBJECT - - - public: - QMultiCheckListItem( TQListView *parent); - ~QMultiCheckListItem() {}; - - virtual bool isOn(int column); - virtual bool isDisabled(int column); - - - protected: - /* reimp */ - virtual void paintCell(TQPainter *, const TQColorGroup &, int, int, int); - - public slots: - virtual void setOn(int, bool); - virtual void toggle(int); - virtual void setDisabled(int, bool); - - signals: - void stateChanged(int, bool); - private: - TQBitArray checkStates; - TQBitArray checkBoxColumns; - TQBitArray disableStates; -}; - -#endif diff --git a/filesharing/advanced/kcm_sambaconf/qmultichectdelistitem.cpp b/filesharing/advanced/kcm_sambaconf/qmultichectdelistitem.cpp new file mode 100644 index 00000000..187289b6 --- /dev/null +++ b/filesharing/advanced/kcm_sambaconf/qmultichectdelistitem.cpp @@ -0,0 +1,159 @@ +/*************************************************************************** + qmultichecklistitem.cpp - description + ------------------- + begin : Sun Jan 26 2003 + copyright : (C) 2003 by Jan Sch�fer + email : janschaefer@users.sourceforge.net + ***************************************************************************/ + +/****************************************************************************** + * * + * This file is part of KSambaPlugin. * + * * + * KSambaPlugin is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * KSambaPlugin 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with KSambaPlugin; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + * * + ******************************************************************************/ + +#include +#include +#include +#include + +#include +#include + +#include "qmultichecklistitem.moc" +#include "qmultichecklistitem.h" + +static const int BoxSize = 16; + + +QMultiCheckListItem::QMultiCheckListItem( TQListView *parent=0) : + TQListViewItem(parent) { +} + +void QMultiCheckListItem::setOn(int column, bool b) { + if (column >= (int) checkBoxColumns.size()) { + checkBoxColumns.resize(column*2); + checkStates.resize(column*2); + } + + checkStates.setBit(column,b); + checkBoxColumns.setBit(column); + kdDebug(5009) << "setOn : " << column << endl; + repaint(); +} + +bool QMultiCheckListItem::isOn(int column) { + return checkStates.testBit(column); +} + +bool QMultiCheckListItem::isDisabled(int column) { + return disableStates.testBit(column); +} + +void QMultiCheckListItem::toggle(int column) { + if (column >= (int) checkBoxColumns.size()) { + checkBoxColumns.resize(column*2); + checkStates.resize(column*2); + } + + checkBoxColumns.setBit(column); + checkStates.toggleBit(column); + emit stateChanged(column,checkStates.testBit(column)); + + repaint(); +} + +void QMultiCheckListItem::setDisabled(int column, bool b) { + if (column >= (int) disableStates.size()) { + disableStates.resize(column*2); + } + + disableStates.setBit(column,b); +// KMessageBox::information(0L,TQString("setDisabled"),TQString("disable %1 ").arg(column)); + repaint(); +} + +void QMultiCheckListItem::paintCell(TQPainter *p,const TQColorGroup & cg, int col, int width, int align) +{ + + if ( !p ) + return; + + TQListView *lv = listView(); + if ( !lv ) + return; + + TQListViewItem::paintCell(p,cg,col,width,align ); + + int marg = lv->itemMargin(); +// int width = BoxSize + marg*2; + // use a provate color group and set the text/highlighted text colors + TQColorGroup mcg = cg; + + if (checkBoxColumns.testBit(col)) { + // Bold/Italic/use default checkboxes + // code allmost identical to TQCheckListItem + Q_ASSERT( lv ); //### + // I use the text color of defaultStyles[0], normalcol in parent listview +// mcg.setColor( TQColorGroup::Text, ((StyleListView*)lv)->normalcol ); + int x = 0; + if ( align == AlignCenter ) { + TQFontMetrics fm( lv->font() ); + x = (width - BoxSize - fm.width(text(0)))/2; + } + int y = (height() - BoxSize) / 2; + + if ( !isEnabled() || disableStates.testBit(col)) + p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) ); + else + p->setPen( TQPen( mcg.text(), 2 ) ); + + if ( isSelected() && lv->header()->mapToSection( 0 ) != 0 ) { + p->fillRect( 0, 0, x + marg + BoxSize + 4, height(), + mcg.brush( TQColorGroup::Highlight ) ); + if ( isEnabled() ) + p->setPen( TQPen( mcg.highlightedText(), 2 ) ); // FIXME! - use defaultstyles[0].selecol. luckily not used :) + } + p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); + x++; + y++; + if ( checkStates.testBit(col) ) { + TQPointArray a( 7*2 ); + int i, xx, yy; + xx = x+1+marg; + yy = y+5; + for ( i=0; i<3; i++ ) { + a.setPoint( 2*i, xx, yy ); + a.setPoint( 2*i+1, xx, yy+2 ); + xx++; yy++; + } + yy -= 2; + for ( i=3; i<7; i++ ) { + a.setPoint( 2*i, xx, yy ); + a.setPoint( 2*i+1, xx, yy+2 ); + xx++; yy--; + } + p->drawLineSegments( a ); + } + + } + + +} + + + diff --git a/filesharing/advanced/kcm_sambaconf/qmultichectdelistitem.h b/filesharing/advanced/kcm_sambaconf/qmultichectdelistitem.h new file mode 100644 index 00000000..b378e228 --- /dev/null +++ b/filesharing/advanced/kcm_sambaconf/qmultichectdelistitem.h @@ -0,0 +1,65 @@ +/*************************************************************************** + qextendedchecklistitem.h - description + ------------------- + begin : Sun Jan 26 2003 + copyright : (C) 2003 by Jan Sch�fer + email : janschaefer@users.sourceforge.net + ***************************************************************************/ + +/****************************************************************************** + * * + * This file is part of KSambaPlugin. * + * * + * KSambaPlugin is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * KSambaPlugin 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with KSambaPlugin; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + * * + ******************************************************************************/ + +#ifndef _TQMULTICHECKLISTITEM_H_ +#define _TQMULTICHECKLISTITEM_H_ + +#include + +#include + +class QMultiCheckListItem : public TQObject, public TQListViewItem { +Q_OBJECT + + + public: + QMultiCheckListItem( TQListView *parent); + ~QMultiCheckListItem() {}; + + virtual bool isOn(int column); + virtual bool isDisabled(int column); + + + protected: + /* reimp */ + virtual void paintCell(TQPainter *, const TQColorGroup &, int, int, int); + + public slots: + virtual void setOn(int, bool); + virtual void toggle(int); + virtual void setDisabled(int, bool); + + signals: + void stateChanged(int, bool); + private: + TQBitArray checkStates; + TQBitArray checkBoxColumns; + TQBitArray disableStates; +}; + +#endif diff --git a/kget/kmainwidget.cpp b/kget/kmainwidget.cpp deleted file mode 100644 index 4e852c66..00000000 --- a/kget/kmainwidget.cpp +++ /dev/null @@ -1,2548 +0,0 @@ -/*************************************************************************** -* kmainwidget.cpp -* ------------------- -* -* begin : Tue Jan 29 2002 -* copyright : (C) 2002 by Patrick Charbonnier -* : Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss -* email : pch@freeshell.org -* Copyright (C) 2002 Carsten Pfeiffer -* -****************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - ***************************************************************************/ -#include -#include -#include -#include -#include - -#ifdef __svr4__ -#define map BULLSHIT // on Solaris it conflicts with STL ? -#include -#undef map -#include // needed for SIOCGIFFLAGS -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "safedelete.h" -#include "settings.h" -#include "transfer.h" -#include "transferlist.h" -#include "kmainwidget.h" -#include "tdefileio.h" -#include "dlgPreferences.h" -#include "logwindow.h" -#include "docking.h" -#include "droptarget.h" -#include - - - -#include -#include -#include - -#include "version.h" -#include "slave.h" -#include "slaveevent.h" - -struct KURLPair -{ - KURL dest; - KURL src; -}; - -TDEMainWidget *kmain = 0L; - -#define LOAD_ICON(X) TDEGlobal::iconLoader()->loadIcon(X, KIcon::MainToolbar) - -DropTarget *kdrop = 0L; - -Settings ksettings; // this object contains all settings - -static int sockets_open(); - - -// socket constants -int ipx_sock = -1; /* IPX socket */ -int ax25_sock = -1; /* AX.25 socket */ -int inet_sock = -1; /* INET socket */ -int ddp_sock = -1; /* Appletalk DDP socket */ - - - -TDEMainWidget::TDEMainWidget(bool bStartDocked) - : KGetIface( "KGet-Interface" ), - TDEMainWindow(0, "kget mainwindow",0), - prefDlg( 0 ), kdock( 0 ) -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - { - TDEConfig cfg( "tdeioslaverc", false, false); - cfg.setGroup(TQString()); - cfg.writeEntry("AutoResume", true); - cfg.sync(); - } - - b_connected = TRUE; - b_viewLogWindow = FALSE; - b_viewPreferences = FALSE; - - myTransferList = 0L; - kmain = this; - - // Set log time, needed for the name of log file - TQDate date = TQDateTime::currentDateTime().date(); - TQTime time = TQDateTime::currentDateTime().time(); - TQString tmp; - - tmp.sprintf("log%d:%d:%d-%d:%d:%d", date.day(), date.month(), date.year(), time.hour(), time.minute(), time.second()); - - logFileName = locateLocal("appdata", "logs/"); - logFileName += tmp; - - lastClipboard = TQApplication::clipboard()->text( TQClipboard::Clipboard ).stripWhiteSpace(); - // Load all settings from TDEConfig - ksettings.load(); - - // Setup log window - logWindow = new LogWindow(); - - m_showDropTarget = false; - - setCaption(KGETVERSION); - - setupGUI(); - setupWhatsThis(); - - log(i18n("Welcome to KGet")); - - setCentralWidget(myTransferList); - - connect(kapp, TQT_SIGNAL(saveYourself()), TQT_SLOT(slotSaveYourself())); - - // Enable dropping - setAcceptDrops(true); - - // Setup connection timer - connectionTimer = new TQTimer(this); - connect(connectionTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotCheckConnection())); - - // setup socket for checking connection - if ((_sock = sockets_open()) < 0) { - log(i18n("Could not create valid socket"), false); - } else { - connectionTimer->start(5000); // 5 second interval for checking connection - } - - checkOnline(); - ksettings.b_offline=( !b_connected || ksettings.b_offlineMode ); - - // Setup animation timer - animTimer = new TQTimer(this); - animCounter = 0; - connect(animTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotAnimTimeout())); - - if (ksettings.b_useAnimation) { - animTimer->start(400); - } else { - animTimer->start(1000); - } - - // Setup transfer timer for scheduled downloads and checkQueue() - transferTimer = new TQTimer(this); - connect(transferTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotTransferTimeout())); - transferTimer->start(10000); // 10 secs time interval - - // Setup autosave timer - autosaveTimer = new TQTimer(this); - connect(autosaveTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotAutosaveTimeout())); - setAutoSave(); - - // Setup clipboard timer - clipboardTimer = new TQTimer(this); - connect(clipboardTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotCheckClipboard())); - if (ksettings.b_autoPaste) { - clipboardTimer->start(1000); - } - - readTransfers(); - - // Setup special windows - kdrop = new DropTarget(this); - kdock = new DockWidget(this); - connect(kdock, TQT_SIGNAL(quitSelected()), TQT_SLOT(slotQuit())); - - // Set geometry - if (ksettings.mainPosition.x() != -1) { - resize(ksettings.mainSize); - move(ksettings.mainPosition); - KWin::setState(winId(), ksettings.mainState); - } else { - resize(650, 180); - } - - // update actions - m_paUseAnimation->setChecked(ksettings.b_useAnimation); - m_paExpertMode->setChecked(ksettings.b_expertMode); - m_paUseLastDir->setChecked(ksettings.b_useLastDir); - - if (ksettings.connectionType != PERMANENT) { - m_paAutoDisconnect->setChecked(ksettings.b_autoDisconnect); - } - setAutoDisconnect(); - - m_paAutoShutdown->setChecked(ksettings.b_autoShutdown); - - - m_paOfflineMode->setChecked(ksettings.b_offline); - if (!ksettings.b_offlineMode) - m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_on")); - - if (ksettings.b_offline) { - setCaption(i18n("Offline"), false); - log(i18n("Starting offline")); - } else - setCaption(TQString(), false); - - m_paAutoPaste->setChecked(ksettings.b_autoPaste); - m_paShowLog->setChecked(b_viewLogWindow); - - if (!bStartDocked && ksettings.b_showMain) - show(); - - kdock->show(); - - KNotifyClient::startDaemon(); - - setStandardToolBarMenuEnabled(true); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -TDEMainWidget::~TDEMainWidget() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - delete prefDlg; - delete kdrop; - writeTransfers(); - writeLog(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif - delete logWindow; -} - - -void TDEMainWidget::log(const TQString & message, bool statusbar) -{ -#ifdef _DEBUG - sDebugIn <<" message= "<< message << endl; -#endif - - logWindow->logGeneral(message); - - if (statusbar) { - statusBar()->message(message, 1000); - } - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotSaveYourself() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - writeTransfers(); - ksettings.save(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::setupGUI() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - // setup transfer list - myTransferList = new TransferList(this, "transferList"); - myTransferList->setSorting(-1); - setListFont(); - - TDEActionCollection *coll = actionCollection(); - - connect(myTransferList, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotUpdateActions())); - connect(myTransferList, TQT_SIGNAL(transferSelected(Transfer *)), this, TQT_SLOT(slotOpenIndividual())); - connect(myTransferList, TQT_SIGNAL(popupMenu(Transfer *)), this, TQT_SLOT(slotPopupMenu(Transfer *))); - - // file actions - m_paOpenTransfer = KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(slotOpenTransfer()), coll, "open_transfer"); - m_paPasteTransfer = KStdAction::paste(TQT_TQOBJECT(this), TQT_SLOT(slotPasteTransfer()), coll, "paste_transfer"); - - m_paExportTransfers = new TDEAction(i18n("&Export Transfer List..."), 0, TQT_TQOBJECT(this), TQT_SLOT(slotExportTransfers()), coll, "export_transfers"); - m_paImportTransfers = new TDEAction(i18n("&Import Transfer List..."), 0, TQT_TQOBJECT(this), TQT_SLOT(slotImportTransfers()), coll, "import_transfers"); - - m_paImportText = new TDEAction(i18n("Import Text &File..."), 0, TQT_TQOBJECT(this), TQT_SLOT(slotImportTextFile()), coll, "import_text"); - - m_paQuit = KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(slotQuit()), coll, "quit"); - - - // transfer actions - m_paCopy = new TDEAction(i18n("&Copy URL to Clipboard"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotCopyToClipboard()), coll, "copy_url"); - m_paIndividual = new TDEAction(i18n("&Open Individual Window"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotOpenIndividual()), coll, "open_individual"); - - m_paMoveToBegin = new TDEAction(i18n("Move to &Beginning"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotMoveToBegin()), coll, "move_begin"); - - m_paMoveToEnd = new TDEAction(i18n("Move to &End"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotMoveToEnd()), coll, "move_end"); -#ifdef _DEBUG - sDebug << "Loading pics" << endl; -#endif - m_paResume = new TDEAction(i18n("&Resume"),"tool_resume", 0, TQT_TQOBJECT(this), TQT_SLOT(slotResumeCurrent()), coll, "resume"); - m_paPause = new TDEAction(i18n("&Pause"),"tool_pause", 0, TQT_TQOBJECT(this), TQT_SLOT(slotPauseCurrent()), coll, "pause"); - m_paDelete = new TDEAction(i18n("&Delete"),"editdelete", TQt::Key_Delete, TQT_TQOBJECT(this), TQT_SLOT(slotDeleteCurrent()), coll, "delete"); - m_paRestart = new TDEAction(i18n("Re&start"),"tool_restart", 0, TQT_TQOBJECT(this), TQT_SLOT(slotRestartCurrent()), coll, "restart"); - - m_paQueue = new TDERadioAction(i18n("&Queue"),"tool_queue", 0, TQT_TQOBJECT(this), TQT_SLOT(slotQueueCurrent()), coll, "queue"); - m_paTimer = new TDERadioAction(i18n("&Timer"),"tool_timer", 0, TQT_TQOBJECT(this), TQT_SLOT(slotTimerCurrent()), coll, "timer"); - m_paDelay = new TDERadioAction(i18n("De&lay"),"tool_delay", 0, TQT_TQOBJECT(this), TQT_SLOT(slotDelayCurrent()), coll, "delay"); - - m_paQueue->setExclusiveGroup("TransferMode"); - m_paTimer->setExclusiveGroup("TransferMode"); - m_paDelay->setExclusiveGroup("TransferMode"); - - // options actions - m_paUseAnimation = new TDEToggleAction(i18n("Use &Animation"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleAnimation()), coll, "toggle_animation"); - m_paExpertMode = new TDEToggleAction(i18n("&Expert Mode"),"tool_expert", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleExpertMode()), coll, "expert_mode"); - m_paUseLastDir = new TDEToggleAction(i18n("&Use-Last-Folder Mode"),"tool_uselastdir", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleUseLastDir()), coll, "use_last_dir"); - m_paAutoDisconnect = new TDEToggleAction(i18n("Auto-&Disconnect Mode"),"tool_disconnect", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleAutoDisconnect()), coll, "auto_disconnect"); - m_paAutoShutdown = new TDEToggleAction(i18n("Auto-S&hutdown Mode"), "tool_shutdown", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleAutoShutdown()), coll, "auto_shutdown"); - m_paOfflineMode = new TDEToggleAction(i18n("&Offline Mode"),"tool_offline_mode_off", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleOfflineMode()), coll, "offline_mode"); - m_paAutoPaste = new TDEToggleAction(i18n("Auto-Pas&te Mode"),"tool_clipboard", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleAutoPaste()), coll, "auto_paste"); - - m_paPreferences = KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotPreferences()), coll); - - KStdAction::keyBindings(guiFactory(), TQT_SLOT(configureShortcuts()), coll); - KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(slotConfigureToolbars()), coll); - KStdAction::configureNotifications(TQT_TQOBJECT(this), TQT_SLOT(slotConfigureNotifications()), coll); - - m_menubarAction = KStdAction::showMenubar(TQT_TQOBJECT(this), TQT_SLOT(slotShowMenubar()), coll, "settings_showmenubar" ); - m_menubarAction->setChecked( !menuBar()->isHidden() ); - - // view actions - createStandardStatusBarAction(); - - m_paShowLog = new TDEToggleAction(i18n("Show &Log Window"),"tool_logwindow", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleLogWindow()), coll, "toggle_log"); - m_paShowLog->setCheckedState(i18n("Hide &Log Window")); - m_paDropTarget = new TDEAction(i18n("Show Drop &Target"),"tool_drop_target", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleDropTarget()), coll, "drop_target"); - m_paKonquerorIntegration = new TDEAction(i18n("Enable &KGet as Konqueror Download Manager"), "konqueror", 0, TQT_TQOBJECT(this), TQT_SLOT(slotKonquerorIntegration()), coll, "konqueror_integration"); - if (ksettings.b_KonquerorIntegration) { - m_paKonquerorIntegration->setText(i18n("Disable &KGet as Konqueror Download Manager")); - } - - menuHelp = new KHelpMenu(this, TDEGlobal::instance()->aboutData()); - KStdAction::whatsThis(menuHelp, TQT_SLOT(contextHelpActivated()), coll, "whats_this"); - - createGUI("kgetui.rc"); - - // setup statusbar - statusBar()->insertFixedItem(i18n(" Transfers: %1 ").arg(99), ID_TOTAL_TRANSFERS); - statusBar()->insertFixedItem(i18n(" Files: %1 ").arg(555), ID_TOTAL_FILES); - statusBar()->insertFixedItem(i18n(" Size: %1 KB ").arg("134.56"), ID_TOTAL_SIZE); - statusBar()->insertFixedItem(i18n(" Time: %1 ").arg(TDEIO::convertSeconds(0)), ID_TOTAL_TIME); - statusBar()->insertFixedItem(i18n(" %1 KB/s ").arg("123.34"), ID_TOTAL_SPEED); - - setAutoSaveSettings( "MainWindow", false /*Settings takes care of size & pos & state */ ); - - slotUpdateActions(); - - updateStatusBar(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::setupWhatsThis() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TQString tmp; - - tmp = i18n("Resume button starts selected transfers\n" "and sets their mode to queued."); - m_paResume->setWhatsThis(tmp); - - tmp = i18n("Pause button stops selected transfers\n" "and sets their mode to delayed."); - m_paPause->setWhatsThis(tmp); - - tmp = i18n("Delete button removes selected transfers\n" "from the list."); - m_paDelete->setWhatsThis(tmp); - - tmp = i18n("Restart button is a convenience button\n" "that simply does Pause and Resume."); - m_paRestart->setWhatsThis(tmp); - - tmp = i18n("Queued button sets the mode of selected\n" "transfers to queued.\n" "\n" "It is a radio button -- you can choose between\n" "three modes."); - m_paQueue->setWhatsThis(tmp); - - tmp = i18n("Scheduled button sets the mode of selected\n" "transfers to scheduled.\n" "\n" "It is a radio button -- you can choose between\n" "three modes."); - m_paTimer->setWhatsThis(tmp); - - tmp = i18n("Delayed button sets the mode of selected\n" "transfers to delayed." "This also causes the selected transfers to stop.\n" "\n" "It is a radio button -- you can choose between\n" "three modes."); - m_paDelay->setWhatsThis(tmp); - - tmp = i18n("Preferences button opens a preferences dialog\n" "where you can set various options.\n" "\n" "Some of these options can be more easily set using the toolbar."); - m_paPreferences->setWhatsThis(tmp); - - tmp = i18n("Log window button opens a log window.\n" "The log window records all program events that occur\n" "while KGet is running."); - m_paShowLog->setWhatsThis(tmp); - - tmp = i18n("Paste transfer button adds a URL from\n" "the clipboard as a new transfer.\n" "\n" "This way you can easily copy&paste URLs between\n" "applications."); - m_paPasteTransfer->setWhatsThis(tmp); - - tmp = i18n("Expert mode button toggles the expert mode\n" "on and off.\n" "\n" "Expert mode is recommended for experienced users.\n" "When set, you will not be \"bothered\" by confirmation\n" "messages.\n" "Important!\n" "Turn it on if you are using auto-disconnect or\n" "auto-shutdown features and you want KGet to disconnect \n" "or shut down without asking."); - m_paExpertMode->setWhatsThis(tmp); - - tmp = i18n("Use last folder button toggles the\n" "use-last-folder feature on and off.\n" "\n" "When set, KGet will ignore the folder settings\n" "and put all new added transfers into the folder\n" "where the last transfer was put."); - m_paUseLastDir->setWhatsThis(tmp); - - tmp = i18n("Auto disconnect button toggles the auto-disconnect\n" "mode on and off.\n" "\n" "When set, KGet will disconnect automatically\n" "after all queued transfers are finished.\n" "\n" "Important!\n" "Also turn on the expert mode when you want KGet\n" "to disconnect without asking."); - m_paAutoDisconnect->setWhatsThis(tmp); - - tmp = i18n("Auto shutdown button toggles the auto-shutdown\n" "mode on and off.\n" "\n" "When set, KGet will quit automatically\n" "after all queued transfers are finished.\n" "Important!\n" "Also turn on the expert mode when you want KGet\n" "to quit without asking."); - m_paAutoShutdown->setWhatsThis(tmp); - - tmp = i18n("Offline mode button toggles the offline mode\n" "on and off.\n" "\n" "When set, KGet will act as if it was not connected\n" "to the Internet.\n" "\n" "You can browse offline, while still being able to add\n" "new transfers as queued."); - m_paOfflineMode->setWhatsThis(tmp); - - tmp = i18n("Auto paste button toggles the auto-paste mode\n" "on and off.\n" "\n" "When set, KGet will periodically scan the clipboard\n" "for URLs and paste them automatically."); - m_paAutoPaste->setWhatsThis(tmp); - - tmp = i18n("Drop target button toggles the window style\n" "between a normal window and a drop target.\n" "\n" "When set, the main window will be hidden and\n" "instead a small shaped window will appear.\n" "\n" "You can show/hide a normal window with a simple click\n" "on a shaped window."); - m_paDropTarget->setWhatsThis(tmp); - /* - tmp = i18n("Dock widget button toggles the window style\n" "between a normal window and a docked widget.\n" "\n" "When set, the main window will be hidden and\n" "instead a docked widget will appear on the panel.\n" "\n" "You can show/hide a normal window by simply clicking\n" "on a docked widget."); - m_paDockWindow->setWhatsThis(tmp); - - tmp = i18n("Normal window button sets\n" "\n" "the window style to normal window"); - m_paNormal->setWhatsThis(tmp); - */ - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotConfigureToolbars() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - saveMainWindowSettings( TDEGlobal::config(), "MainWindow" ); - KEditToolbar edit(factory()); - connect(&edit, TQT_SIGNAL( newToolbarConfig() ), this, TQT_SLOT( slotNewToolbarConfig() )); - edit.exec(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotNewToolbarConfig() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - createGUI("kgetui.rc"); - applyMainWindowSettings( TDEGlobal::config(), "MainWindow" ); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotImportTextFile() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TQString tmpFile; - TQString list; - int i, j; - - KURL filename = KFileDialog::getOpenURL(ksettings.lastDirectory); - if (!filename.isValid()) - return; - - if (TDEIO::NetAccess::download(filename, tmpFile, this)) { - list = kFileToString(tmpFile); - TDEIO::NetAccess::removeTempFile(tmpFile); - } else - list = kFileToString(filename.path()); // file not accessible -> give error message - - i = 0; - while ((j = list.find('\n', i)) != -1) { - TQString newtransfer = list.mid(i, j - i); - addTransfer(newtransfer); - i = j + 1; - } - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotImportTransfers() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - readTransfers(true); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::readTransfers(bool ask_for_name) -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - KURL url; - - if (ask_for_name) - url = KFileDialog::getOpenURL(ksettings.lastDirectory, i18n("*.kgt|*.kgt\n*|All Files")); - else - url.setPath( locateLocal("appdata", "transfers.kgt") ); - - readTransfersEx(url); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - -void TDEMainWidget::readTransfersEx(const KURL & file) -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - if (!file.isValid()) { - -#ifdef _DEBUG - sDebugOut<< " string empty" << endl; -#endif - return; - } -#ifdef _DEBUG - sDebug << "Read from file: " << file << endl; -#endif - myTransferList->readTransfers(file); - checkQueue(); - slotTransferTimeout(); - myTransferList->clearSelection(); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotExportTransfers() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - writeTransfers(true); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - -void TDEMainWidget::writeTransfers(bool ask_for_name) -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TQString str; - TQString txt; - - if (ask_for_name) - txt = KFileDialog::getSaveFileName(ksettings.lastDirectory, i18n("*.kgt|*.kgt\n*|All Files")); - else - txt = locateLocal("appdata", "transfers.kgt"); - - - - if (txt.isEmpty()) - { -#ifdef _DEBUG - sDebugOut<< " because Destination File name isEmpty"<< endl; -#endif - return; - } - if (!txt.endsWith(".kgt")) - txt += ".kgt"; - -#ifdef _DEBUG - sDebug << "Writing transfers " << txt << endl; -#endif - - myTransferList->writeTransfers(txt); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::writeLog() -{ -#ifdef _DEBUG - sDebugIn << "Writing log to file : " << logFileName.ascii() << endl; -#endif - - - kCStringToFile(logWindow->getText().local8Bit(), logFileName, false, false); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotQuit() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - Transfer *item; - TransferIterator it(myTransferList); - - log(i18n("Quitting...")); - - for (; it.current(); ++it) { - item = it.current(); - if (item->getStatus() == Transfer::ST_RUNNING && !ksettings.b_expertMode) { - if (KMessageBox::warningContinueCancel(this, i18n("Some transfers are still running.\nAre you sure you want to quit KGet?"), i18n("Warning"), KStdGuiItem::quit()) != KMessageBox::Continue) { -#ifdef _DEBUG - sDebugOut << endl; -#endif - - return; - } - break; - } - } - - ksettings.save(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif - - kapp->quit(); -} - - -void TDEMainWidget::slotResumeCurrent() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TransferIterator it(myTransferList); - - for (; it.current(); ++it) - if (it.current()->isSelected()) - it.current()->slotResume(); - slotUpdateActions(); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotPauseCurrent() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TransferIterator it(myTransferList); - - m_paPause->setEnabled(false); - m_paRestart->setEnabled(false); - update(); - - for (; it.current(); ++it) - if (it.current()->isSelected()) - it.current()->slotRequestPause(); - slotUpdateActions(); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - - -void TDEMainWidget::slotRestartCurrent() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TransferIterator it(myTransferList); - - for (; it.current(); ++it) - if (it.current()->isSelected()) - it.current()->slotRequestRestart(); - slotUpdateActions(); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotDeleteCurrent() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - m_paDelete->setEnabled(false); - m_paPause->setEnabled(false); - update(); - TransferIterator it(myTransferList); - TQValueList > selectedItems; - TQStringList itemNames; - - while (it.current()) { - if (it.current()->isSelected()) { - selectedItems.append( TQGuardedPtr( it.current() )); - itemNames.append( it.current()->getSrc().prettyURL() ); - } - ++it; - } - - if (!ksettings.b_expertMode) - { - if ( selectedItems.count() > 1 ) - { - if (KMessageBox::warningContinueCancelList(this, i18n("Are you sure you want to delete these transfers?"), - itemNames, i18n("Question"), - KStdGuiItem::del(), - TQString("multiple_delete_transfer")) - != KMessageBox::Continue) - return; // keep 'em - } - else - { - if (KMessageBox::warningContinueCancel(this, i18n("Are you sure you want to delete this transfer?"), - i18n("Question"), KStdGuiItem::del(), - TQString("delete_transfer")) - != KMessageBox::Continue) - return; - } - } - - // If we reach this, we want to delete all selected transfers - // Some of them might have finished in the meantime tho. Good that - // we used a TQGuardedPtr :) - - int transferFinishedMeanwhile = 0; - TQValueListConstIterator > lit = selectedItems.begin();; - while ( lit != selectedItems.end() ) - { - if ( *lit ) - (*lit)->slotRequestRemove(); - else - ++transferFinishedMeanwhile; - - ++lit; - } - - checkQueue(); // needed ! - - if ( !ksettings.b_expertMode && transferFinishedMeanwhile > 0 ) - KMessageBox::information(this, i18n("The transfer you wanted to delete completed before it could be deleted.", - "%n transfers you wanted to delete completed before they could be deleted.", - transferFinishedMeanwhile ), - TQString(), "completedBeforeDeletion" ); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::stopAll() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - log(i18n("Stopping all jobs"), false); - - TransferIterator it(myTransferList); - Transfer::TransferStatus Status; - for (; it.current(); ++it) { - Status = it.current()->getStatus(); - if (Status == Transfer::ST_TRYING || Status == Transfer::ST_RUNNING) - it.current()->slotStop(); - } - slotUpdateActions(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotQueueCurrent() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TransferIterator it(myTransferList); - - for (; it.current(); ++it) { - if (it.current()->isSelected()) { - it.current()->slotQueue(); - } - } - - // myTransferList->clearSelection(); - slotUpdateActions(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotTimerCurrent() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - - TransferIterator it(myTransferList); - - for (; it.current(); ++it) - if (it.current()->isSelected()) - it.current()->slotRequestSchedule(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif - -} - - -void TDEMainWidget::slotDelayCurrent() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TransferIterator it(myTransferList); - - for (; it.current(); ++it) - if (it.current()->isSelected()) - it.current()->slotRequestDelay(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotOpenTransfer() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TQString newtransfer; - bool ok = false; - -#ifdef _DEBUG - // newtransfer = "ftp://localhost/home/pch/test.gz"; - // newtransfer = "http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.18.tar.gz"; - newtransfer = "ftp://darkmoon/pub/test.gz"; -#endif - - while (!ok) { - newtransfer = KInputDialog::getText(i18n("Open Transfer"), i18n("Open transfer:"), newtransfer, &ok, this); - - // user presses cancel - if (!ok) { - return; - } - - KURL url = KURL::fromPathOrURL(newtransfer); - - if (!url.isValid()) { - KMessageBox::error(this, i18n("Malformed URL:\n%1").arg(newtransfer), i18n("Error")); - ok = false; - } - } - - addTransfer(newtransfer); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - - -void TDEMainWidget::slotCheckClipboard() -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - TQString clipData = TQApplication::clipboard()->text( TQClipboard::Clipboard ).stripWhiteSpace(); - - if (clipData != lastClipboard) { - sDebug << "New clipboard event" << endl; - - lastClipboard = clipData; - if ( lastClipboard.isEmpty() ) - return; - - KURL url = KURL::fromPathOrURL( lastClipboard ); - - if (url.isValid() && !url.isLocalFile()) - slotPasteTransfer(); - } - -#ifdef _DEBUG - //sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotPasteTransfer() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - TQString newtransfer; - - newtransfer = TQApplication::clipboard()->text(); - newtransfer = newtransfer.stripWhiteSpace(); - - if (!ksettings.b_expertMode) { - bool ok = false; - newtransfer = KInputDialog::getText(i18n("Open Transfer"), i18n("Open transfer:"), newtransfer, &ok, this); - - if (!ok) { - // cancelled -#ifdef _DEBUG - sDebugOut << endl; -#endif - return; - } - - } - - if (!newtransfer.isEmpty()) - addTransfer(newtransfer); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - -// destFile must be a filename, not a directory! And it will be deleted, if -// it exists already, without further notice. -void TDEMainWidget::addTransferEx(const KURL& url, const KURL& destFile) -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - if ( !sanityChecksSuccessful( url ) ) - return; - - KURL destURL = destFile; - - // Malformed destination url means one of two things. - // 1) The URL is empty. - // 2) The URL is only a filename, like a default (suggested) filename. - if ( !destURL.isValid() ) - { - // Setup destination - TQString destDir = getSaveDirectoryFor( url.fileName() ); - bool b_expertMode = ksettings.b_expertMode; - bool bDestisMalformed = true; - - while (bDestisMalformed) - { - if (!b_expertMode) { - // open the filedialog for confirmation - KFileDialog dlg( destDir, TQString(), - 0L, "save_as", true); - dlg.setCaption(i18n("Save As")); - dlg.setOperationMode(KFileDialog::Saving); - - // Use the destination name if not empty... - if (destURL.isEmpty()) - dlg.setSelection(url.fileName()); - else - dlg.setSelection(destURL.url()); - - if ( dlg.exec() == TQDialog::Rejected ) - { -#ifdef _DEBUG - sDebugOut << endl; -#endif - return; - } - else - { - destURL = dlg.selectedURL(); - ksettings.lastDirectory = destURL.directory(); - } - } - else { - // in expert mode don't open the filedialog - // if destURL is not empty, it's the suggested filename - destURL = KURL::fromPathOrURL( destDir + "/" + - ( destURL.isEmpty() ? - url.fileName() : destURL.url() )); - } - - //check if destination already exists - if(TDEIO::NetAccess::exists(destURL, false, this)) - { - if (KMessageBox::warningYesNo(this,i18n("Destination file \n%1\nalready exists.\nDo you want to overwrite it?").arg( destURL.prettyURL()), TQString(), i18n("Overwrite"), i18n("Do Not Overwrite") ) - == KMessageBox::Yes) - { - bDestisMalformed=false; - SafeDelete::deleteFile( destURL ); - } - else - { - b_expertMode=false; - ksettings.lastDirectory = destURL.directory(); - } - } - else - bDestisMalformed=false; - } - } - - else // destURL was given, check whether the file exists already - { - // simply delete it, the calling process should have asked if you - // really want to delete (at least tdehtml does) - if(TDEIO::NetAccess::exists(destURL, false, this)) - SafeDelete::deleteFile( destURL ); - } - - // create a new transfer item - Transfer *item = myTransferList->addTransfer(url, destURL); - KNotifyClient::event(kdock->winId(), "added", i18n("%1 has been added.").arg(url.prettyURL())); - item->updateAll(); // update the remaining fields - - if (ksettings.b_showIndividual) - item->showIndividual(); - - myTransferList->clearSelection(); - - checkQueue(); -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::addTransfers( const KURL::List& src, const TQString& destDir ) -{ - TQValueList urls_orig; - - for ( KURL::List::ConstIterator it = src.begin(); it != src.end(); ++it ) - { - KURLPair url; - url.src = *it; - if ( url.src.fileName().endsWith( ".kgt" ) ) - readTransfersEx(url.src); - else - urls_orig.append( url ); - } - - if ( urls_orig.isEmpty() ) - return; - - if ( urls_orig.count() == 1 ) // just one file -> ask for filename - { - KURL destFile; - - if ( !destDir.isEmpty() ) - { - // create a proper destination file from destDir - KURL destURL = KURL::fromPathOrURL( destDir ); - TQString fileName = urls_orig.first().src.fileName(); - - // in case the fileName is empty, we simply ask for a filename in - // addTransferEx. Do NOT attempt to use an empty filename, that - // would be a directory (and we don't want to overwrite that!) - if ( !fileName.isEmpty() ) - { - destURL.adjustPath( +1 ); - destURL.setFileName( fileName ); - if(TDEIO::NetAccess::exists(destURL, false, this)) - { - if (KMessageBox::warningYesNo(this,i18n("Destination file \n%1\nalready exists.\nDo you want to overwrite it?").arg( destURL.prettyURL()), TQString(), i18n("Overwrite"), i18n("Do Not Overwrite") ) - == KMessageBox::Yes) - { - SafeDelete::deleteFile( destURL ); - destFile = destURL; - } - } - else - { - destFile = destURL; - } - } - } - - addTransferEx( urls_orig.first().src, destFile ); - return; - } - - // multiple files -> ask for directory, not for every single filename - - bool dir_accepted = false; - TQValueList::Iterator it; - TQValueList urls; - KURL::List urlsToDelete; - while ( !dir_accepted ) - { - urlsToDelete.clear(); - urls = urls_orig; // copy the list here, urls might be changed, yet when we return here (Cancel), - // we want to start again with the original list - dir_accepted = true; //Set to false later when Cancel is pressed - KURL dest; - if ( destDir.isEmpty() || !TQFileInfo( destDir ).isDir() ) - { - if ( !destDir.isEmpty() ) - dest.setPath( destDir ); - else - dest.setPath( getSaveDirectoryFor( src.first().fileName() ) ); - - // ask in any case, when destDir is empty - if ( destDir.isEmpty() || !TQFileInfo( dest.path() ).isDir() ) - { - TQString dir = KFileDialog::getExistingDirectory( dest.path() ); - if ( dir.isEmpty() ) // aborted - return; - - dest.setPath( dir ); - ksettings.lastDirectory = dir; - } - } - - // dest is now finally the real destination directory for all the files - dest.adjustPath(+1); - - // create new transfer items - bool skip_all = false; - bool overwrite_all = false; - it = urls.begin(); - TDEIO::RenameDlg_Result result; - while ( it != urls.end() ) - { - - if ( !sanityChecksSuccessful( (*it).src ) ) - { - it = urls.erase( it ); - continue; // shouldn't we notify the user?? - } - - (*it).dest = dest; - TQString fileName = (*it).src.fileName(); - if ( fileName.isEmpty() ) // simply use the full url as filename - fileName = KURL::encode_string_no_slash( (*it).src.prettyURL() ); - - (*it).dest.setFileName( fileName ); - - if( TDEIO::NetAccess::exists((*it).dest, false, this)) - { - TQString newdest; - if (skip_all) - result = TDEIO::R_SKIP; - else if( overwrite_all ) - result = TDEIO::R_OVERWRITE; - else - { - TQFileInfo finfo( (*it).dest.path() ); - TQString caption = i18n( "File Already exists" ) + " - KGet"; - result = TDEIO::open_RenameDlg( caption, (*it).src.url(), (*it).dest.url(), TDEIO::RenameDlg_Mode(TDEIO::M_OVERWRITE|TDEIO::M_SKIP|TDEIO::M_MULTI), newdest, (TDEIO::filesize_t) -1, (TDEIO::filesize_t)finfo.size(), (time_t) -1, (time_t) -1, (time_t) -1, finfo.lastModified().toTime_t()); - } - switch (result) - { - case TDEIO::R_RENAME: - (*it).dest = KURL::fromPathOrURL( newdest ); - break; - case TDEIO::R_OVERWRITE_ALL: - overwrite_all = true; //fall through - case TDEIO::R_OVERWRITE: - urlsToDelete.append( (*it).dest ); - break; - case TDEIO::R_AUTO_SKIP: - skip_all = true; - case TDEIO::R_SKIP: //fall through - it = urls.erase( it ); - continue; - break; - default: // Cancel, ask again for directory - dir_accepted = false; - } - if ( !dir_accepted ) - break; - } // if(TDEIO::NetAccess::exists - ++it; - } // while ( it != urls.end() ) - } // while ( !dir_accepted ) - - KURL::List::Iterator it_1 = urlsToDelete.begin(); - for ( ; it_1 != urlsToDelete.end(); ++it_1 ) - { - SafeDelete::deleteFile( *it_1 ); - } - - int numdl = 0; - it = urls.begin(); - for ( ; it != urls.end(); ++it ) - { - Transfer *item = myTransferList->addTransfer((*it).src, (*it).dest); - item->updateAll(); // update the remaining fields - numdl++; - } - - KNotifyClient::event(kdock->winId(), "added", i18n("1 download has been added.", "%n downloads have been added.", numdl)); - - myTransferList->clearSelection(); - - checkQueue(); -} - -void TDEMainWidget::addTransfer(const TQString& src) -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - if ( src.isEmpty() ) - return; - - addTransferEx( KURL::fromPathOrURL( src ) ); - -#ifdef _DEBUG - sDebugOut << endl; -#endif - -} - - -void TDEMainWidget::checkQueue() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - uint numRun = 0; - int status; - Transfer *item; - TransferIterator it(myTransferList); - - if (!ksettings.b_offline) { - - // count running transfers - for (; it.current(); ++it) { - status = it.current()->getStatus(); - if (status == Transfer::ST_RUNNING || status == Transfer::ST_TRYING) - numRun++; - } - sDebug << "Found " << numRun << " Running Jobs" << endl; - it.reset(); - bool isRunning; - bool isQuequed; - for (; it.current() && numRun < ksettings.maxSimultaneousConnections; ++it) { - item = it.current(); - isRunning = (item->getStatus() == Transfer::ST_RUNNING) || ((item->getStatus() == Transfer::ST_TRYING)); - - isQuequed = (item->getMode() == Transfer::MD_QUEUED || item->getMode() == Transfer::MD_NEW); - - if (!isRunning && isQuequed && !ksettings.b_offline) - { - log(i18n("Starting another queued job.")); - item->slotResume(); - numRun++; - } - } - - slotUpdateActions(); - - updateStatusBar(); - -// } else {//TODO this has to be solved different -// log(i18n("Cannot continue offline status")); - } - - it.reset(); - for (; it.current(); ++it) - { - item = it.current(); - if (item->getMode() == Transfer::MD_NEW && item->getStatus() == Transfer::ST_STOPPED) - { - item->checkCache(); - } - } -#ifdef _DEBUG - sDebugOut << endl; -#endif - -} - - -void TDEMainWidget::slotAnimTimeout() -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - bool isTransfer; - - animCounter++; - if (animCounter == myTransferList->getPhasesNum()) { - //updateStatusBar(); - animCounter = 0; - } - // update status of all items of transferList - isTransfer = myTransferList->updateStatus(animCounter); - - //if (this->isVisible()) { - updateStatusBar(); - //} -#ifdef _DEBUG - //sDebugOut << endl; -#endif - -} - - -void TDEMainWidget::slotTransferTimeout() -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - Transfer *item; - TransferIterator it(myTransferList); - - bool flag = false; - - for (; it.current(); ++it) { - item = it.current(); - if (item->getMode() == Transfer::MD_SCHEDULED && item->getStartTime() <= TQDateTime::currentDateTime()) { - item->setMode(Transfer::MD_QUEUED); - flag = true; - } - } - - if (flag) { - checkQueue(); - } - - if (ksettings.b_autoDisconnect && ksettings.b_timedDisconnect && ksettings.disconnectTime <= TQTime::currentTime() && ksettings.disconnectDate == TQDate::currentDate()) { - onlineDisconnect(); - } - -#ifdef _DEBUG - //sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotAutosaveTimeout() -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - writeTransfers(); - -#ifdef _DEBUG - //sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotStatusChanged(Transfer * item, int _operation) -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - switch (_operation) { - - case Transfer::OP_FINISHED: - { - TQString srcurl = item->getSrc().prettyURL(); - if (ksettings.b_removeOnSuccess && !item->keepDialogOpen() ) - { - delete item; - item = 0L; - } - else - item->setMode(Transfer::MD_NONE); - - if (!myTransferList->areTransfersQueuedOrScheduled()) { - // no items or only delayed and finished items in the TransferList - if (ksettings.b_autoDisconnect) - onlineDisconnect(); - - if (ksettings.b_autoShutdown) { - slotQuit(); - return; - } - KNotifyClient::event(kdock->winId(), "finishedall", i18n("All the downloads are finished.")); - } - else - { - KNotifyClient::event(kdock->winId(), "finished", i18n("%1 successfully downloaded.").arg(srcurl)); - } - - if ( item ) - item->slotUpdateActions(); - - break; - } - case Transfer::OP_RESUMED: - slotUpdateActions(); - item->slotUpdateActions(); - // play(ksettings.audioStarted); - break; - case Transfer::OP_PAUSED: - break; - case Transfer::OP_REMOVED: - delete item; - return; // checkQueue() will be called only once after all deletions - - case Transfer::OP_ABORTED: - break; - case Transfer::OP_DELAYED: - case Transfer::OP_QUEUED: - slotUpdateActions(); - item->slotUpdateActions(); - break; - case Transfer::OP_SCHEDULED: - slotUpdateActions(); - item->slotUpdateActions(); - slotTransferTimeout(); // this will check schedule times - return; // checkQueue() is called from slotTransferTimeout() - } - checkQueue(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::dragEnterEvent(TQDragEnterEvent * event) -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - event->accept(KURLDrag::canDecode(event) || TQTextDrag::canDecode(event)); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::dropEvent(TQDropEvent * event) -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - KURL::List list; - TQString str; - - if (KURLDrag::decode(event, list)) { - addTransfers(list); - } else if (TQTextDrag::decode(event, str)) { - addTransfer(str); - } - sDebugOut << endl; -} - - -void TDEMainWidget::slotCopyToClipboard() -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - Transfer *item = (Transfer *) myTransferList->currentItem(); - - if (item) { - TQString url = item->getSrc().url(); - TQClipboard *cb = TQApplication::clipboard(); - cb->setText( url, TQClipboard::Selection ); - cb->setText( url, TQClipboard::Clipboard); - myTransferList->clearSelection(); - } - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotMoveToBegin() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - myTransferList->moveToBegin((Transfer *) myTransferList->currentItem()); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotMoveToEnd() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - myTransferList->moveToEnd((Transfer *) myTransferList->currentItem()); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotOpenIndividual() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - Transfer *item = (Transfer *) myTransferList->currentItem(); - if (item) - item->showIndividual(); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - -bool TDEMainWidget::queryClose() -{ - if( kapp->sessionSaving()) - return true; - hide(); - return false; -} - -void TDEMainWidget::setAutoSave() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - autosaveTimer->stop(); - if (ksettings.b_autoSave) { - autosaveTimer->start(ksettings.autoSaveInterval * 60000); - } - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - - -void TDEMainWidget::setAutoDisconnect() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - // disable action when we are connected permanently - m_paAutoDisconnect->setEnabled(ksettings.connectionType != PERMANENT); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - -void TDEMainWidget::slotPreferences() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - if ( !prefDlg ) - prefDlg = new DlgPreferences(this); - - prefDlg->show(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - -void TDEMainWidget::slotConfigureNotifications() -{ - KNotifyDialog::configure(this); -} - -void TDEMainWidget::slotToggleLogWindow() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - b_viewLogWindow = !b_viewLogWindow; - if (b_viewLogWindow) - logWindow->show(); - else - logWindow->hide(); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotToggleAnimation() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - ksettings.b_useAnimation = !ksettings.b_useAnimation; - - if (!ksettings.b_useAnimation && animTimer->isActive()) { - animTimer->stop(); - animTimer->start(1000); - animCounter = 0; - } else { - animTimer->stop(); - animTimer->start(400); - } - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - -void TDEMainWidget::slotToggleOfflineMode() -{ -#ifdef _DEBUG - sDebugIn "ksettings.b_offlineMode = " << ksettings.b_offlineMode << endl; -#endif - - ksettings.b_offlineMode = !ksettings.b_offlineMode; - ksettings.b_offline=(ksettings.b_offlineMode || !b_connected); - if (ksettings.b_offline) { - log(i18n("Offline mode on.")); - stopAll(); - setCaption(i18n("Offline"), false); - m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_off")); - } else { - log(i18n("Offline mode off.")); - setCaption(TQString(), false); - m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_on")); - } - - m_paOfflineMode->setChecked(ksettings.b_offline); - - - slotUpdateActions(); - checkQueue(); -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotToggleExpertMode() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - ksettings.b_expertMode = !ksettings.b_expertMode; - - if (ksettings.b_expertMode) { - log(i18n("Expert mode on.")); - } else { - log(i18n("Expert mode off.")); - } - m_paExpertMode->setChecked(ksettings.b_expertMode); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotToggleUseLastDir() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - ksettings.b_useLastDir = !ksettings.b_useLastDir; - - if (ksettings.b_useLastDir) { - log(i18n("Use last folder on.")); - } else { - log(i18n("Use last folder off.")); - } - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotToggleAutoDisconnect() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - ksettings.b_autoDisconnect = !ksettings.b_autoDisconnect; - - if (ksettings.b_autoDisconnect) { - log(i18n("Auto disconnect on.")); - } else { - log(i18n("Auto disconnect off.")); - } - m_paAutoDisconnect->setChecked(ksettings.b_autoDisconnect); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotToggleAutoShutdown() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - ksettings.b_autoShutdown = !ksettings.b_autoShutdown; - - if (ksettings.b_autoShutdown) { - log(i18n("Auto shutdown on.")); - } else { - log(i18n("Auto shutdown off.")); - } - - m_paAutoShutdown->setChecked(ksettings.b_autoShutdown); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotToggleAutoPaste() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - ksettings.b_autoPaste = !ksettings.b_autoPaste; - - if (ksettings.b_autoPaste) { - log(i18n("Auto paste on.")); - clipboardTimer->start(1000); - } else { - log(i18n("Auto paste off.")); - clipboardTimer->stop(); - } - m_paAutoPaste->setChecked(ksettings.b_autoPaste); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotToggleDropTarget() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - m_showDropTarget = !m_showDropTarget; - - if (m_showDropTarget) { - kdrop->show(); - kdrop->updateStickyState(); - m_paDropTarget->setText(i18n("Hide Drop &Target")); - } - else { - kdrop->hide(); - m_paDropTarget->setText(i18n("Show Drop &Target")); - } - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotKonquerorIntegration() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - bool bIsKonquiEnable=!ksettings.b_KonquerorIntegration; - ksettings.b_KonquerorIntegration=!ksettings.b_KonquerorIntegration; - TDEConfig cfg("konquerorrc", false, false); - cfg.setGroup("HTML Settings"); - cfg.writePathEntry("DownloadManager",TQString((bIsKonquiEnable)?"kget":"")); - cfg.sync(); - if (bIsKonquiEnable) - { - m_paKonquerorIntegration->setText(i18n("Disable &KGet as Konqueror Download Manager")); - } - else - { - m_paKonquerorIntegration->setText(i18n("Enable &KGet as Konqueror Download Manager")); - } - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotPopupMenu(Transfer * item) -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - // select current item - myTransferList->setCurrentItem(item); - - // set action properties - slotUpdateActions(); - - // popup transfer menu at the position - TQWidget *menu = guiFactory()->container("transfer",this); - ((TQPopupMenu *) menu)->popup(TQCursor::pos()); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::setListFont() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - myTransferList->setFont(ksettings.listViewFont); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - -void TDEMainWidget::slotUpdateActions() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - - // disable all signals - m_paQueue->blockSignals(true); - m_paTimer->blockSignals(true); - m_paDelay->blockSignals(true); - - // at first turn off all buttons like when nothing is selected - m_paQueue->setChecked(false); - m_paTimer->setChecked(false); - m_paDelay->setChecked(false); - - m_paQueue->setEnabled(false); - m_paTimer->setEnabled(false); - m_paDelay->setEnabled(false); - - m_paDelete->setEnabled(false); - m_paResume->setEnabled(false); - m_paPause->setEnabled(false); - m_paRestart->setEnabled(false); - - m_paCopy->setEnabled(false); - m_paIndividual->setEnabled(false); - m_paMoveToBegin->setEnabled(false); - m_paMoveToEnd->setEnabled(false); - - Transfer *item; - Transfer *first_item = 0L; - TransferIterator it(myTransferList); - int index = 0; - int totals_items = 0; - int sel_items = 0; - - for (; it.current(); ++it, ++totals_items) { - - // update action on visibles windows - if (it.current()->isVisible()) - it.current()->slotUpdateActions(); - - if (it.current()->isSelected()) { - item = it.current(); - sel_items = totals_items; - index++; // counting number of selected items - if (index == 1) { - first_item = item; // store first selected item - if (totals_items > 0) - m_paMoveToBegin->setEnabled(true); - - m_paMoveToEnd->setEnabled(true); - } else { - - m_paMoveToBegin->setEnabled(false); - m_paMoveToEnd->setEnabled(false); - } - // enable PAUSE, RESUME and RESTART only when we are online and not in offline mode -#ifdef _DEBUG - sDebug << "-->ONLINE= " << ksettings.b_offline << endl; -#endif - if (item == first_item && !ksettings.b_offline) { - switch (item->getStatus()) { - case Transfer::ST_TRYING: - case Transfer::ST_RUNNING: - m_paResume->setEnabled(false); - m_paPause->setEnabled(true); - m_paRestart->setEnabled(true); - break; - case Transfer::ST_STOPPED: - m_paResume->setEnabled(true); - m_paPause->setEnabled(false); - m_paRestart->setEnabled(false); -#ifdef _DEBUG - sDebug << "STATUS IS stopped" << item->getStatus() << endl; -#endif - break; - case Transfer::ST_FINISHED: - m_paResume->setEnabled(false); - m_paPause->setEnabled(false); - m_paRestart->setEnabled(false); - break; - - - } //end switch - - } else if (item->getStatus() != first_item->getStatus()) { - // disable all when all selected items don't have the same status - m_paResume->setEnabled(false); - m_paPause->setEnabled(false); - m_paRestart->setEnabled(false); - } - - - if (item == first_item) { - m_paDelete->setEnabled(true); - m_paCopy->setEnabled(true); - m_paIndividual->setEnabled(true); - if (item->getStatus() != Transfer::ST_FINISHED) { - m_paQueue->setEnabled(true); - m_paTimer->setEnabled(true); - m_paDelay->setEnabled(true); - - switch (item->getMode()) { - case Transfer::MD_QUEUED: -#ifdef _DEBUG - sDebug << "....................THE MODE IS MD_QUEUED " << item->getMode() << endl; -#endif - m_paQueue->setChecked(true); - break; - case Transfer::MD_SCHEDULED: -#ifdef _DEBUG - sDebug << "....................THE MODE IS MD_SCHEDULED " << item->getMode() << endl; -#endif - m_paTimer->setChecked(true); - break; - case Transfer::MD_DELAYED: -#ifdef _DEBUG - sDebug << "....................THE MODE IS MD_DELAYED " << item->getMode() << endl; -#endif - m_paDelay->setChecked(true); - break; - } - } - } else if (item->getMode() != first_item->getMode()) { - // unset all when all selected items don't have the same mode - m_paQueue->setChecked(false); - m_paTimer->setChecked(false); - m_paDelay->setChecked(false); - m_paMoveToBegin->setEnabled(false); - m_paMoveToEnd->setEnabled(false); - m_paQueue->setEnabled(false); - m_paTimer->setEnabled(false); - m_paDelay->setEnabled(false); - } - - } // when item is selected - } // loop - - - - if (sel_items == totals_items - 1) - m_paMoveToEnd->setEnabled(false); - - // enable all signals - - - - m_paQueue->blockSignals(false); - m_paTimer->blockSignals(false); - m_paDelay->blockSignals(false); - - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::updateStatusBar() -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - Transfer *item; - TQString tmpstr; - - int totalFiles = 0; - TDEIO::filesize_t totalSize = 0; - int totalSpeed = 0; - unsigned int remTime = 0; - - TransferIterator it(myTransferList); - - for (; it.current(); ++it) { - item = it.current(); - if (item->getTotalSize() != 0) { - totalSize += (item->getTotalSize() - item->getProcessedSize()); - } - totalFiles++; - totalSpeed += item->getSpeed(); - - if (item->getRemainingTime() > remTime) { - remTime = item->getRemainingTime(); - } - } - - statusBar()->changeItem(i18n(" Transfers: %1 ").arg(myTransferList->childCount()), ID_TOTAL_TRANSFERS); - statusBar()->changeItem(i18n(" Files: %1 ").arg(totalFiles), ID_TOTAL_FILES); - statusBar()->changeItem(i18n(" Size: %1 ").arg(TDEIO::convertSize(totalSize)), ID_TOTAL_SIZE); - statusBar()->changeItem(i18n(" Time: %1 ").arg(TDEIO::convertSeconds(remTime)), ID_TOTAL_TIME); - statusBar()->changeItem(i18n(" %1/s ").arg(TDEIO::convertSize(totalSpeed)), ID_TOTAL_SPEED); - //update size for each statusbar field - statusBar()->setItemFixed(ID_TOTAL_TRANSFERS, -1); - statusBar()->setItemFixed(ID_TOTAL_FILES, -1); - statusBar()->setItemFixed(ID_TOTAL_SIZE, -1); - statusBar()->setItemFixed(ID_TOTAL_TIME, -1); - statusBar()->setItemFixed(ID_TOTAL_SPEED, -1); - - if (kdock) { - tmpstr = i18n("Transfers: %1 ").arg(myTransferList->childCount()) + - i18n("
Files: %1 ").arg(totalFiles) + - i18n("
Size: %1 ").arg(TDEIO::convertSize(totalSize)) + - i18n("
Time: %1 ").arg(TDEIO::convertSeconds(remTime)) + - i18n("
Speed: %1/s").arg(TDEIO::convertSize(totalSpeed)); - kdock->updateToolTip( tmpstr ); - //trayicon changes if download is in progress - if (totalSpeed == 0) - { - kdock->changeIcon( "kget_dock" ); - } - else - { - kdock->changeIcon( "kget_dock_download" ); - } - } -#ifdef _DEBUG - //sDebugOut << endl; -#endif -} - - -void TDEMainWidget::onlineDisconnect() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - if (!b_connected) { - return; - } - - if (!ksettings.b_expertMode) { - if (KMessageBox::questionYesNo(this, i18n("Do you really want to disconnect?"), - i18n("Question"), - i18n("Disconnect"), i18n("Stay Connected"), - "kget_AutoOnlineDisconnect") - != KMessageBox::Yes) { - return; - } - } - log(i18n("Disconnecting...")); - system(TQFile::encodeName(ksettings.disconnectCommand)); - -#ifdef _DEBUG - sDebugOut << endl; -#endif -} - - -void TDEMainWidget::slotCheckConnection() -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - bool old = b_connected; - checkOnline(); - if (b_connected != old) { - if (b_connected) { - log(i18n("We are online.")); - setCaption(TQString(), false); - ksettings.b_offline=ksettings.b_offlineMode; - checkQueue(); - } else { - log(i18n("We are offline.")); - setCaption(i18n("Offline"), false); - ksettings.b_offline=true; - stopAll(); - } - } -#ifdef _DEBUG - //sDebugOut << endl; -#endif -} - - -void TDEMainWidget::checkOnline() -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - struct ifreq ifr; - - memset(&ifr, 0, sizeof(ifreq)); - - // setup the device name according to the type of connection and link number - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", ConnectionDevices[ksettings.connectionType].ascii(), ksettings.linkNumber); - - bool flag = false; - - if (ksettings.connectionType != PERMANENT) { - // get the flags for particular device - if (ioctl(_sock, SIOCGIFFLAGS, &ifr) < 0) { - flag = true; - b_connected = false; - } else if (ifr.ifr_flags == 0) { -#ifdef _DEBUG - sDebug << "Can't get flags from interface " << ifr.ifr_name << endl; -#endif - b_connected = false; - } else if (ifr.ifr_flags & IFF_UP) { // if (ifr.ifr_flags & IFF_RUNNING) - b_connected = true; - } else { - b_connected = false; - } - } else { - b_connected = true; // PERMANENT connection - } - - m_paOfflineMode->setEnabled(b_connected); - - if (flag) { -#ifdef _DEBUG - sDebug << "Unknown interface " << ifr.ifr_name << endl; -#endif - } -#ifdef _DEBUG - //sDebugOut << endl; -#endif -} - - -// Helper method for opening device socket - - - - -static int sockets_open() -{ -#ifdef _DEBUG - sDebugIn << endl; -#endif - - inet_sock = socket(AF_INET, SOCK_DGRAM, 0); -#ifdef AF_IPX - ipx_sock = socket(AF_IPX, SOCK_DGRAM, 0); -#else - ipx_sock = -1; -#endif - -#ifdef AF_AX25 - ax25_sock = socket(AF_AX25, SOCK_DGRAM, 0); -#else - ax25_sock = -1; -#endif - - ddp_sock = socket(AF_APPLETALK, SOCK_DGRAM, 0); - /* - * Now pick any (exisiting) useful socket family for generic queries - */ - - sDebug << "<<< sockets_open () " << endl; - if (inet_sock != -1) - return inet_sock; - if (ipx_sock != -1) - return ipx_sock; - if (ax25_sock != -1) - return ax25_sock; - /* - * If this is -1 we have no known network layers and its time to jump. - */ - -#ifdef _DEBUG - sDebugOut << endl; -#endif - - return ddp_sock; -} - - -/** No descriptions */ -void TDEMainWidget::customEvent(TQCustomEvent * _e) -{ -#ifdef _DEBUG - //sDebugIn << endl; -#endif - - - SlaveEvent *e = (SlaveEvent *) _e; - unsigned int result = e->getEvent(); - - switch (result) { - - // running cases.. - case Slave::SLV_PROGRESS_SIZE: - e->getItem()->slotProcessedSize(e->getData()); - break; - case Slave::SLV_PROGRESS_SPEED: - e->getItem()->slotSpeed(e->getData()); - break; - - case Slave::SLV_RESUMED: - e->getItem()->slotExecResume(); - break; - - // stopping cases - case Slave::SLV_FINISHED: - e->getItem()->slotFinished(); - break; - case Slave::SLV_PAUSED: - e->getItem()->slotExecPause(); - break; - case Slave::SLV_SCHEDULED: - e->getItem()->slotExecSchedule(); - break; - - case Slave::SLV_DELAYED: - e->getItem()->slotExecDelay(); - break; - case Slave::SLV_CONNECTED: - e->getItem()->slotExecConnected(); - break; - - case Slave::SLV_CAN_RESUME: - e->getItem()->slotCanResume((bool) e->getData()); - break; - - case Slave::SLV_TOTAL_SIZE: - e->getItem()->slotTotalSize(e->getData()); - break; - - case Slave::SLV_ERROR: - e->getItem()->slotExecError(); - break; - - case Slave::SLV_BROKEN: - e->getItem()->slotExecBroken(); - break; - - case Slave::SLV_REMOVED: - e->getItem()->slotExecRemove(); - break; - - case Slave::SLV_INFO: - e->getItem()->logMessage(e->getMsg()); - break; - - case Slave::SLV_NOTINCACHE: - e->getItem()->NotInCache(); - break; - default: -#ifdef _DEBUG - sDebug << "Unknown Result..die" << result << endl; -#endif - assert(0); - } - - -#ifdef _DEBUG - //sDebugOut << endl; -#endif -} - -TQString TDEMainWidget::getSaveDirectoryFor( const TQString& filename ) const -{ - // first set destination directory to current directory ( which is also last used ) - TQString destDir = ksettings.lastDirectory; - - if (!ksettings.b_useLastDir) { - // check wildcards for default directory - DirList::Iterator it; - for (it = ksettings.defaultDirList.begin(); it != ksettings.defaultDirList.end(); ++it) { - TQRegExp rexp((*it).extRegexp); - - rexp.setWildcard(true); - - if ((rexp.search( filename )) != -1) { - destDir = (*it).defaultDir; - break; - } - } - } - - return destDir; -} - -bool TDEMainWidget::sanityChecksSuccessful( const KURL& url ) -{ - if (!url.isValid() || !KProtocolInfo::supportsReading( url ) ) - { - if (!ksettings.b_expertMode) - KMessageBox::error(this, i18n("Malformed URL:\n%1").arg(url.prettyURL()), i18n("Error")); - - return false; - } - // if we find this URL in the list - Transfer *transfer = myTransferList->find( url ); - if ( transfer ) - { - if ( transfer->getStatus() != Transfer::ST_FINISHED ) - { - if ( !ksettings.b_expertMode ) - { - KMessageBox::error(this, i18n("Already saving URL\n%1").arg(url.prettyURL()), i18n("Error")); - } - - transfer->showIndividual(); - return false; - } - - else // transfer is finished, ask if we want to download again - { - if ( ksettings.b_expertMode || - (KMessageBox::questionYesNo(this, i18n("Already saved URL\n%1\nDownload again?").arg(url.prettyURL()),i18n("Question"),i18n("Download Again"),KStdGuiItem::cancel() ) - == KMessageBox::Yes) ) - { - transfer->slotRequestRemove(); - checkQueue(); - return true; - } - } - - return false; - } - - // why restrict this to ftp and http? (pfeiffer) -// // don't download file URL's TODO : uncomment? -// if (url.protocol() == "http" && url.protocol() != "ftp") { -// KMessageBox::error(this, i18n("File protocol not accepted!\n%1").arg(url.prettyURL()), i18n("Error")); -// #ifdef _DEBUG -// sDebugOut << endl; -// #endif -// return false; -// } - - return true; -} - -bool TDEMainWidget::isDropTargetVisible() const -{ - return m_showDropTarget; -} - -void TDEMainWidget::setDropTargetVisible( bool setVisible ) -{ - if ( setVisible != isDropTargetVisible() ) - { - m_paDropTarget->activate(); - } -} - -void TDEMainWidget::setOfflineMode( bool offline ) -{ - if ( ksettings.b_offlineMode != offline ) - slotToggleOfflineMode(); -} - -bool TDEMainWidget::isOfflineMode() const -{ - return ksettings.b_offlineMode; -} - -void TDEMainWidget::activateDropTarget() -{ - setDropTargetVisible( true ); -} - -void TDEMainWidget::slotShowMenubar() -{ - if(m_menubarAction->isChecked()) - menuBar()->show(); - else - menuBar()->hide(); -} - -#include "kmainwidget.moc" diff --git a/kget/kmainwidget.h b/kget/kmainwidget.h deleted file mode 100644 index cd2ce92d..00000000 --- a/kget/kmainwidget.h +++ /dev/null @@ -1,233 +0,0 @@ -/*************************************************************************** -* kmainwidget.h -* ------------------- -* -* Revision : $Id$ -* begin : Tue Jan 29 2002 -* copyright : (C) 2002 by Patrick Charbonnier -* : Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss -* email : pch@freeshell.org -* -****************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - ***************************************************************************/ - - -#ifndef _KMAINWIDGET_H_ -#define _KMAINWIDGET_H_ - -#include -#include -#include -#include "common.h" - -#include "kget_iface.h" - -class TDEAction; -//class TDEToggleAction; -class TDERadioAction; - -class DockWidget; -class DropTarget; -class LogWindow; -class DlgPreferences; - -class Transfer; -class TransferList; -class Settings; - - -class TDEMainWidget:public TDEMainWindow, virtual public KGetIface -{ - - Q_OBJECT - - -public: - enum StatusbarFields { ID_TOTAL_TRANSFERS = 1, ID_TOTAL_FILES, ID_TOTAL_SIZE, - ID_TOTAL_TIME , ID_TOTAL_SPEED }; - - TDEMainWidget(bool bShowMain = false); - ~TDEMainWidget(); - - void addTransfer( const TQString& src ); - void addTransferEx( const KURL& url, - const KURL& destFile = KURL()); - - // dcop interface - virtual void addTransfers( const KURL::List& src, const TQString& destDir = TQString() ); - virtual bool isDropTargetVisible() const; - virtual void setDropTargetVisible( bool setVisible ); - - - void checkQueue(); - - void setListFont(); - void setAutoSave(); - void setAutoDisconnect(); - - LogWindow *logwin()const { return logWindow;} - friend class Settings; - - // Actions - TDEToggleAction *m_paShowLog; - TDEToggleAction *m_menubarAction; - TDEAction *m_paPreferences; - TDEAction *m_paQuit; - bool b_viewLogWindow; - - void readTransfersEx(const KURL & url); - - void activateDropTarget(); - -public slots: - void slotPasteTransfer(); - void slotToggleLogWindow(); - void slotPreferences(); - void slotConfigureNotifications(); - void slotToggleExpertMode(); - void slotToggleOfflineMode(); - void slotToggleUseLastDir(); - void slotToggleAutoDisconnect(); - void slotToggleAutoShutdown(); - void slotToggleAutoPaste(); - void slotToggleDropTarget(); - void slotToggleAnimation(); - void slotUpdateActions(); - void slotKonquerorIntegration(); - -protected slots: - void slotQuit(); - - void slotOpenTransfer(); - void slotExportTransfers(); - void slotImportTransfers(); - void slotImportTextFile(); - - void slotSaveYourself(); - void slotCheckConnection(); - - - void slotStatusChanged(Transfer * item, int _operation); - - void slotResumeCurrent(); - void slotPauseCurrent(); - void slotDeleteCurrent(); - void slotRestartCurrent(); - - void slotQueueCurrent(); - void slotTimerCurrent(); - void slotDelayCurrent(); - - void slotOpenIndividual(); - - void slotAnimTimeout(); - void slotTransferTimeout(); - void slotAutosaveTimeout(); - - void slotMoveToBegin(); - void slotMoveToEnd(); - - void slotCopyToClipboard(); - void slotCheckClipboard(); - - void slotConfigureToolbars(); - void slotNewToolbarConfig(); - void slotShowMenubar(); - - void slotPopupMenu(Transfer * item); - -protected: - virtual void setOfflineMode( bool online ); - virtual bool isOfflineMode() const; - virtual bool queryClose(); - void writeLog(); - - // drag and drop - virtual void dragEnterEvent(TQDragEnterEvent *); - virtual void dropEvent(TQDropEvent *); - - void readTransfers(bool ask_for_name = false); - void writeTransfers(bool ask_for_name = false); - - - void setupGUI(); - void setupWhatsThis(); - - void updateStatusBar(); - - // some flags - bool b_connected; - bool b_viewPreferences; - - // utility functions - void onlineDisconnect(); - void checkOnline(); - void stopAll(); - void log(const TQString & message, bool statusbar = true); - - /** No descriptions */ - virtual void customEvent(TQCustomEvent * e); - - // various timers - TQTimer *animTimer; // animation timer - TQTimer *connectionTimer; // timer that checks whether we are online - TQTimer *transferTimer; // timer for scheduled transfers - TQTimer *autosaveTimer; // timer for autosaving transfer list - TQTimer *clipboardTimer; // timer for checking clipboard - autopaste function - - TQString logFileName; - - - -private: - TQString getSaveDirectoryFor( const TQString& filename ) const; - bool sanityChecksSuccessful( const KURL& url ); - - TransferList * myTransferList; - KHelpMenu *menuHelp; - - LogWindow *logWindow; - DlgPreferences *prefDlg; - DockWidget *kdock; - - TQString lastClipboard; - - uint animCounter; - - int _sock; - - // Actions - TDEAction *m_paOpenTransfer, *m_paPasteTransfer, *m_paExportTransfers, *m_paImportTransfers; - TDEAction *m_paImportText; - - TDEAction *m_paMoveToBegin, *m_paMoveToEnd, *m_paCopy, *m_paIndividual; - TDEAction *m_paResume, *m_paPause, *m_paDelete, *m_paRestart; - TDERadioAction *m_paQueue, *m_paTimer, *m_paDelay; - - TDEToggleAction *m_paUseAnimation; - TDEToggleAction *m_paExpertMode, *m_paUseLastDir, *m_paOfflineMode; - TDEToggleAction *m_paAutoDisconnect, *m_paAutoShutdown, *m_paAutoPaste; - - TDEAction *m_paDropTarget; - TDEAction *m_paKonquerorIntegration; - bool m_showDropTarget; - -}; - -extern TDEMainWidget *kmain; -extern DropTarget *kdrop; - -#endif // _KMAINWIDGET_H_ diff --git a/kget/tdemainwidget.cpp b/kget/tdemainwidget.cpp new file mode 100644 index 00000000..4e852c66 --- /dev/null +++ b/kget/tdemainwidget.cpp @@ -0,0 +1,2548 @@ +/*************************************************************************** +* kmainwidget.cpp +* ------------------- +* +* begin : Tue Jan 29 2002 +* copyright : (C) 2002 by Patrick Charbonnier +* : Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss +* email : pch@freeshell.org +* Copyright (C) 2002 Carsten Pfeiffer +* +****************************************************************************/ + +/*************************************************************************** + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + ***************************************************************************/ +#include +#include +#include +#include +#include + +#ifdef __svr4__ +#define map BULLSHIT // on Solaris it conflicts with STL ? +#include +#undef map +#include // needed for SIOCGIFFLAGS +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "safedelete.h" +#include "settings.h" +#include "transfer.h" +#include "transferlist.h" +#include "kmainwidget.h" +#include "tdefileio.h" +#include "dlgPreferences.h" +#include "logwindow.h" +#include "docking.h" +#include "droptarget.h" +#include + + + +#include +#include +#include + +#include "version.h" +#include "slave.h" +#include "slaveevent.h" + +struct KURLPair +{ + KURL dest; + KURL src; +}; + +TDEMainWidget *kmain = 0L; + +#define LOAD_ICON(X) TDEGlobal::iconLoader()->loadIcon(X, KIcon::MainToolbar) + +DropTarget *kdrop = 0L; + +Settings ksettings; // this object contains all settings + +static int sockets_open(); + + +// socket constants +int ipx_sock = -1; /* IPX socket */ +int ax25_sock = -1; /* AX.25 socket */ +int inet_sock = -1; /* INET socket */ +int ddp_sock = -1; /* Appletalk DDP socket */ + + + +TDEMainWidget::TDEMainWidget(bool bStartDocked) + : KGetIface( "KGet-Interface" ), + TDEMainWindow(0, "kget mainwindow",0), + prefDlg( 0 ), kdock( 0 ) +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + { + TDEConfig cfg( "tdeioslaverc", false, false); + cfg.setGroup(TQString()); + cfg.writeEntry("AutoResume", true); + cfg.sync(); + } + + b_connected = TRUE; + b_viewLogWindow = FALSE; + b_viewPreferences = FALSE; + + myTransferList = 0L; + kmain = this; + + // Set log time, needed for the name of log file + TQDate date = TQDateTime::currentDateTime().date(); + TQTime time = TQDateTime::currentDateTime().time(); + TQString tmp; + + tmp.sprintf("log%d:%d:%d-%d:%d:%d", date.day(), date.month(), date.year(), time.hour(), time.minute(), time.second()); + + logFileName = locateLocal("appdata", "logs/"); + logFileName += tmp; + + lastClipboard = TQApplication::clipboard()->text( TQClipboard::Clipboard ).stripWhiteSpace(); + // Load all settings from TDEConfig + ksettings.load(); + + // Setup log window + logWindow = new LogWindow(); + + m_showDropTarget = false; + + setCaption(KGETVERSION); + + setupGUI(); + setupWhatsThis(); + + log(i18n("Welcome to KGet")); + + setCentralWidget(myTransferList); + + connect(kapp, TQT_SIGNAL(saveYourself()), TQT_SLOT(slotSaveYourself())); + + // Enable dropping + setAcceptDrops(true); + + // Setup connection timer + connectionTimer = new TQTimer(this); + connect(connectionTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotCheckConnection())); + + // setup socket for checking connection + if ((_sock = sockets_open()) < 0) { + log(i18n("Could not create valid socket"), false); + } else { + connectionTimer->start(5000); // 5 second interval for checking connection + } + + checkOnline(); + ksettings.b_offline=( !b_connected || ksettings.b_offlineMode ); + + // Setup animation timer + animTimer = new TQTimer(this); + animCounter = 0; + connect(animTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotAnimTimeout())); + + if (ksettings.b_useAnimation) { + animTimer->start(400); + } else { + animTimer->start(1000); + } + + // Setup transfer timer for scheduled downloads and checkQueue() + transferTimer = new TQTimer(this); + connect(transferTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotTransferTimeout())); + transferTimer->start(10000); // 10 secs time interval + + // Setup autosave timer + autosaveTimer = new TQTimer(this); + connect(autosaveTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotAutosaveTimeout())); + setAutoSave(); + + // Setup clipboard timer + clipboardTimer = new TQTimer(this); + connect(clipboardTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotCheckClipboard())); + if (ksettings.b_autoPaste) { + clipboardTimer->start(1000); + } + + readTransfers(); + + // Setup special windows + kdrop = new DropTarget(this); + kdock = new DockWidget(this); + connect(kdock, TQT_SIGNAL(quitSelected()), TQT_SLOT(slotQuit())); + + // Set geometry + if (ksettings.mainPosition.x() != -1) { + resize(ksettings.mainSize); + move(ksettings.mainPosition); + KWin::setState(winId(), ksettings.mainState); + } else { + resize(650, 180); + } + + // update actions + m_paUseAnimation->setChecked(ksettings.b_useAnimation); + m_paExpertMode->setChecked(ksettings.b_expertMode); + m_paUseLastDir->setChecked(ksettings.b_useLastDir); + + if (ksettings.connectionType != PERMANENT) { + m_paAutoDisconnect->setChecked(ksettings.b_autoDisconnect); + } + setAutoDisconnect(); + + m_paAutoShutdown->setChecked(ksettings.b_autoShutdown); + + + m_paOfflineMode->setChecked(ksettings.b_offline); + if (!ksettings.b_offlineMode) + m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_on")); + + if (ksettings.b_offline) { + setCaption(i18n("Offline"), false); + log(i18n("Starting offline")); + } else + setCaption(TQString(), false); + + m_paAutoPaste->setChecked(ksettings.b_autoPaste); + m_paShowLog->setChecked(b_viewLogWindow); + + if (!bStartDocked && ksettings.b_showMain) + show(); + + kdock->show(); + + KNotifyClient::startDaemon(); + + setStandardToolBarMenuEnabled(true); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +TDEMainWidget::~TDEMainWidget() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + delete prefDlg; + delete kdrop; + writeTransfers(); + writeLog(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif + delete logWindow; +} + + +void TDEMainWidget::log(const TQString & message, bool statusbar) +{ +#ifdef _DEBUG + sDebugIn <<" message= "<< message << endl; +#endif + + logWindow->logGeneral(message); + + if (statusbar) { + statusBar()->message(message, 1000); + } + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotSaveYourself() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + writeTransfers(); + ksettings.save(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::setupGUI() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + // setup transfer list + myTransferList = new TransferList(this, "transferList"); + myTransferList->setSorting(-1); + setListFont(); + + TDEActionCollection *coll = actionCollection(); + + connect(myTransferList, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotUpdateActions())); + connect(myTransferList, TQT_SIGNAL(transferSelected(Transfer *)), this, TQT_SLOT(slotOpenIndividual())); + connect(myTransferList, TQT_SIGNAL(popupMenu(Transfer *)), this, TQT_SLOT(slotPopupMenu(Transfer *))); + + // file actions + m_paOpenTransfer = KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(slotOpenTransfer()), coll, "open_transfer"); + m_paPasteTransfer = KStdAction::paste(TQT_TQOBJECT(this), TQT_SLOT(slotPasteTransfer()), coll, "paste_transfer"); + + m_paExportTransfers = new TDEAction(i18n("&Export Transfer List..."), 0, TQT_TQOBJECT(this), TQT_SLOT(slotExportTransfers()), coll, "export_transfers"); + m_paImportTransfers = new TDEAction(i18n("&Import Transfer List..."), 0, TQT_TQOBJECT(this), TQT_SLOT(slotImportTransfers()), coll, "import_transfers"); + + m_paImportText = new TDEAction(i18n("Import Text &File..."), 0, TQT_TQOBJECT(this), TQT_SLOT(slotImportTextFile()), coll, "import_text"); + + m_paQuit = KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(slotQuit()), coll, "quit"); + + + // transfer actions + m_paCopy = new TDEAction(i18n("&Copy URL to Clipboard"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotCopyToClipboard()), coll, "copy_url"); + m_paIndividual = new TDEAction(i18n("&Open Individual Window"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotOpenIndividual()), coll, "open_individual"); + + m_paMoveToBegin = new TDEAction(i18n("Move to &Beginning"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotMoveToBegin()), coll, "move_begin"); + + m_paMoveToEnd = new TDEAction(i18n("Move to &End"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotMoveToEnd()), coll, "move_end"); +#ifdef _DEBUG + sDebug << "Loading pics" << endl; +#endif + m_paResume = new TDEAction(i18n("&Resume"),"tool_resume", 0, TQT_TQOBJECT(this), TQT_SLOT(slotResumeCurrent()), coll, "resume"); + m_paPause = new TDEAction(i18n("&Pause"),"tool_pause", 0, TQT_TQOBJECT(this), TQT_SLOT(slotPauseCurrent()), coll, "pause"); + m_paDelete = new TDEAction(i18n("&Delete"),"editdelete", TQt::Key_Delete, TQT_TQOBJECT(this), TQT_SLOT(slotDeleteCurrent()), coll, "delete"); + m_paRestart = new TDEAction(i18n("Re&start"),"tool_restart", 0, TQT_TQOBJECT(this), TQT_SLOT(slotRestartCurrent()), coll, "restart"); + + m_paQueue = new TDERadioAction(i18n("&Queue"),"tool_queue", 0, TQT_TQOBJECT(this), TQT_SLOT(slotQueueCurrent()), coll, "queue"); + m_paTimer = new TDERadioAction(i18n("&Timer"),"tool_timer", 0, TQT_TQOBJECT(this), TQT_SLOT(slotTimerCurrent()), coll, "timer"); + m_paDelay = new TDERadioAction(i18n("De&lay"),"tool_delay", 0, TQT_TQOBJECT(this), TQT_SLOT(slotDelayCurrent()), coll, "delay"); + + m_paQueue->setExclusiveGroup("TransferMode"); + m_paTimer->setExclusiveGroup("TransferMode"); + m_paDelay->setExclusiveGroup("TransferMode"); + + // options actions + m_paUseAnimation = new TDEToggleAction(i18n("Use &Animation"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleAnimation()), coll, "toggle_animation"); + m_paExpertMode = new TDEToggleAction(i18n("&Expert Mode"),"tool_expert", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleExpertMode()), coll, "expert_mode"); + m_paUseLastDir = new TDEToggleAction(i18n("&Use-Last-Folder Mode"),"tool_uselastdir", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleUseLastDir()), coll, "use_last_dir"); + m_paAutoDisconnect = new TDEToggleAction(i18n("Auto-&Disconnect Mode"),"tool_disconnect", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleAutoDisconnect()), coll, "auto_disconnect"); + m_paAutoShutdown = new TDEToggleAction(i18n("Auto-S&hutdown Mode"), "tool_shutdown", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleAutoShutdown()), coll, "auto_shutdown"); + m_paOfflineMode = new TDEToggleAction(i18n("&Offline Mode"),"tool_offline_mode_off", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleOfflineMode()), coll, "offline_mode"); + m_paAutoPaste = new TDEToggleAction(i18n("Auto-Pas&te Mode"),"tool_clipboard", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleAutoPaste()), coll, "auto_paste"); + + m_paPreferences = KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotPreferences()), coll); + + KStdAction::keyBindings(guiFactory(), TQT_SLOT(configureShortcuts()), coll); + KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(slotConfigureToolbars()), coll); + KStdAction::configureNotifications(TQT_TQOBJECT(this), TQT_SLOT(slotConfigureNotifications()), coll); + + m_menubarAction = KStdAction::showMenubar(TQT_TQOBJECT(this), TQT_SLOT(slotShowMenubar()), coll, "settings_showmenubar" ); + m_menubarAction->setChecked( !menuBar()->isHidden() ); + + // view actions + createStandardStatusBarAction(); + + m_paShowLog = new TDEToggleAction(i18n("Show &Log Window"),"tool_logwindow", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleLogWindow()), coll, "toggle_log"); + m_paShowLog->setCheckedState(i18n("Hide &Log Window")); + m_paDropTarget = new TDEAction(i18n("Show Drop &Target"),"tool_drop_target", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleDropTarget()), coll, "drop_target"); + m_paKonquerorIntegration = new TDEAction(i18n("Enable &KGet as Konqueror Download Manager"), "konqueror", 0, TQT_TQOBJECT(this), TQT_SLOT(slotKonquerorIntegration()), coll, "konqueror_integration"); + if (ksettings.b_KonquerorIntegration) { + m_paKonquerorIntegration->setText(i18n("Disable &KGet as Konqueror Download Manager")); + } + + menuHelp = new KHelpMenu(this, TDEGlobal::instance()->aboutData()); + KStdAction::whatsThis(menuHelp, TQT_SLOT(contextHelpActivated()), coll, "whats_this"); + + createGUI("kgetui.rc"); + + // setup statusbar + statusBar()->insertFixedItem(i18n(" Transfers: %1 ").arg(99), ID_TOTAL_TRANSFERS); + statusBar()->insertFixedItem(i18n(" Files: %1 ").arg(555), ID_TOTAL_FILES); + statusBar()->insertFixedItem(i18n(" Size: %1 KB ").arg("134.56"), ID_TOTAL_SIZE); + statusBar()->insertFixedItem(i18n(" Time: %1 ").arg(TDEIO::convertSeconds(0)), ID_TOTAL_TIME); + statusBar()->insertFixedItem(i18n(" %1 KB/s ").arg("123.34"), ID_TOTAL_SPEED); + + setAutoSaveSettings( "MainWindow", false /*Settings takes care of size & pos & state */ ); + + slotUpdateActions(); + + updateStatusBar(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::setupWhatsThis() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TQString tmp; + + tmp = i18n("Resume button starts selected transfers\n" "and sets their mode to queued."); + m_paResume->setWhatsThis(tmp); + + tmp = i18n("Pause button stops selected transfers\n" "and sets their mode to delayed."); + m_paPause->setWhatsThis(tmp); + + tmp = i18n("Delete button removes selected transfers\n" "from the list."); + m_paDelete->setWhatsThis(tmp); + + tmp = i18n("Restart button is a convenience button\n" "that simply does Pause and Resume."); + m_paRestart->setWhatsThis(tmp); + + tmp = i18n("Queued button sets the mode of selected\n" "transfers to queued.\n" "\n" "It is a radio button -- you can choose between\n" "three modes."); + m_paQueue->setWhatsThis(tmp); + + tmp = i18n("Scheduled button sets the mode of selected\n" "transfers to scheduled.\n" "\n" "It is a radio button -- you can choose between\n" "three modes."); + m_paTimer->setWhatsThis(tmp); + + tmp = i18n("Delayed button sets the mode of selected\n" "transfers to delayed." "This also causes the selected transfers to stop.\n" "\n" "It is a radio button -- you can choose between\n" "three modes."); + m_paDelay->setWhatsThis(tmp); + + tmp = i18n("Preferences button opens a preferences dialog\n" "where you can set various options.\n" "\n" "Some of these options can be more easily set using the toolbar."); + m_paPreferences->setWhatsThis(tmp); + + tmp = i18n("Log window button opens a log window.\n" "The log window records all program events that occur\n" "while KGet is running."); + m_paShowLog->setWhatsThis(tmp); + + tmp = i18n("Paste transfer button adds a URL from\n" "the clipboard as a new transfer.\n" "\n" "This way you can easily copy&paste URLs between\n" "applications."); + m_paPasteTransfer->setWhatsThis(tmp); + + tmp = i18n("Expert mode button toggles the expert mode\n" "on and off.\n" "\n" "Expert mode is recommended for experienced users.\n" "When set, you will not be \"bothered\" by confirmation\n" "messages.\n" "Important!\n" "Turn it on if you are using auto-disconnect or\n" "auto-shutdown features and you want KGet to disconnect \n" "or shut down without asking."); + m_paExpertMode->setWhatsThis(tmp); + + tmp = i18n("Use last folder button toggles the\n" "use-last-folder feature on and off.\n" "\n" "When set, KGet will ignore the folder settings\n" "and put all new added transfers into the folder\n" "where the last transfer was put."); + m_paUseLastDir->setWhatsThis(tmp); + + tmp = i18n("Auto disconnect button toggles the auto-disconnect\n" "mode on and off.\n" "\n" "When set, KGet will disconnect automatically\n" "after all queued transfers are finished.\n" "\n" "Important!\n" "Also turn on the expert mode when you want KGet\n" "to disconnect without asking."); + m_paAutoDisconnect->setWhatsThis(tmp); + + tmp = i18n("Auto shutdown button toggles the auto-shutdown\n" "mode on and off.\n" "\n" "When set, KGet will quit automatically\n" "after all queued transfers are finished.\n" "Important!\n" "Also turn on the expert mode when you want KGet\n" "to quit without asking."); + m_paAutoShutdown->setWhatsThis(tmp); + + tmp = i18n("Offline mode button toggles the offline mode\n" "on and off.\n" "\n" "When set, KGet will act as if it was not connected\n" "to the Internet.\n" "\n" "You can browse offline, while still being able to add\n" "new transfers as queued."); + m_paOfflineMode->setWhatsThis(tmp); + + tmp = i18n("Auto paste button toggles the auto-paste mode\n" "on and off.\n" "\n" "When set, KGet will periodically scan the clipboard\n" "for URLs and paste them automatically."); + m_paAutoPaste->setWhatsThis(tmp); + + tmp = i18n("Drop target button toggles the window style\n" "between a normal window and a drop target.\n" "\n" "When set, the main window will be hidden and\n" "instead a small shaped window will appear.\n" "\n" "You can show/hide a normal window with a simple click\n" "on a shaped window."); + m_paDropTarget->setWhatsThis(tmp); + /* + tmp = i18n("Dock widget button toggles the window style\n" "between a normal window and a docked widget.\n" "\n" "When set, the main window will be hidden and\n" "instead a docked widget will appear on the panel.\n" "\n" "You can show/hide a normal window by simply clicking\n" "on a docked widget."); + m_paDockWindow->setWhatsThis(tmp); + + tmp = i18n("Normal window button sets\n" "\n" "the window style to normal window"); + m_paNormal->setWhatsThis(tmp); + */ + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotConfigureToolbars() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + saveMainWindowSettings( TDEGlobal::config(), "MainWindow" ); + KEditToolbar edit(factory()); + connect(&edit, TQT_SIGNAL( newToolbarConfig() ), this, TQT_SLOT( slotNewToolbarConfig() )); + edit.exec(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotNewToolbarConfig() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + createGUI("kgetui.rc"); + applyMainWindowSettings( TDEGlobal::config(), "MainWindow" ); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotImportTextFile() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TQString tmpFile; + TQString list; + int i, j; + + KURL filename = KFileDialog::getOpenURL(ksettings.lastDirectory); + if (!filename.isValid()) + return; + + if (TDEIO::NetAccess::download(filename, tmpFile, this)) { + list = kFileToString(tmpFile); + TDEIO::NetAccess::removeTempFile(tmpFile); + } else + list = kFileToString(filename.path()); // file not accessible -> give error message + + i = 0; + while ((j = list.find('\n', i)) != -1) { + TQString newtransfer = list.mid(i, j - i); + addTransfer(newtransfer); + i = j + 1; + } + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotImportTransfers() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + readTransfers(true); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::readTransfers(bool ask_for_name) +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + KURL url; + + if (ask_for_name) + url = KFileDialog::getOpenURL(ksettings.lastDirectory, i18n("*.kgt|*.kgt\n*|All Files")); + else + url.setPath( locateLocal("appdata", "transfers.kgt") ); + + readTransfersEx(url); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + +void TDEMainWidget::readTransfersEx(const KURL & file) +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + if (!file.isValid()) { + +#ifdef _DEBUG + sDebugOut<< " string empty" << endl; +#endif + return; + } +#ifdef _DEBUG + sDebug << "Read from file: " << file << endl; +#endif + myTransferList->readTransfers(file); + checkQueue(); + slotTransferTimeout(); + myTransferList->clearSelection(); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotExportTransfers() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + writeTransfers(true); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + +void TDEMainWidget::writeTransfers(bool ask_for_name) +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TQString str; + TQString txt; + + if (ask_for_name) + txt = KFileDialog::getSaveFileName(ksettings.lastDirectory, i18n("*.kgt|*.kgt\n*|All Files")); + else + txt = locateLocal("appdata", "transfers.kgt"); + + + + if (txt.isEmpty()) + { +#ifdef _DEBUG + sDebugOut<< " because Destination File name isEmpty"<< endl; +#endif + return; + } + if (!txt.endsWith(".kgt")) + txt += ".kgt"; + +#ifdef _DEBUG + sDebug << "Writing transfers " << txt << endl; +#endif + + myTransferList->writeTransfers(txt); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::writeLog() +{ +#ifdef _DEBUG + sDebugIn << "Writing log to file : " << logFileName.ascii() << endl; +#endif + + + kCStringToFile(logWindow->getText().local8Bit(), logFileName, false, false); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotQuit() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + Transfer *item; + TransferIterator it(myTransferList); + + log(i18n("Quitting...")); + + for (; it.current(); ++it) { + item = it.current(); + if (item->getStatus() == Transfer::ST_RUNNING && !ksettings.b_expertMode) { + if (KMessageBox::warningContinueCancel(this, i18n("Some transfers are still running.\nAre you sure you want to quit KGet?"), i18n("Warning"), KStdGuiItem::quit()) != KMessageBox::Continue) { +#ifdef _DEBUG + sDebugOut << endl; +#endif + + return; + } + break; + } + } + + ksettings.save(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif + + kapp->quit(); +} + + +void TDEMainWidget::slotResumeCurrent() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TransferIterator it(myTransferList); + + for (; it.current(); ++it) + if (it.current()->isSelected()) + it.current()->slotResume(); + slotUpdateActions(); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotPauseCurrent() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TransferIterator it(myTransferList); + + m_paPause->setEnabled(false); + m_paRestart->setEnabled(false); + update(); + + for (; it.current(); ++it) + if (it.current()->isSelected()) + it.current()->slotRequestPause(); + slotUpdateActions(); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + + +void TDEMainWidget::slotRestartCurrent() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TransferIterator it(myTransferList); + + for (; it.current(); ++it) + if (it.current()->isSelected()) + it.current()->slotRequestRestart(); + slotUpdateActions(); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotDeleteCurrent() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + m_paDelete->setEnabled(false); + m_paPause->setEnabled(false); + update(); + TransferIterator it(myTransferList); + TQValueList > selectedItems; + TQStringList itemNames; + + while (it.current()) { + if (it.current()->isSelected()) { + selectedItems.append( TQGuardedPtr( it.current() )); + itemNames.append( it.current()->getSrc().prettyURL() ); + } + ++it; + } + + if (!ksettings.b_expertMode) + { + if ( selectedItems.count() > 1 ) + { + if (KMessageBox::warningContinueCancelList(this, i18n("Are you sure you want to delete these transfers?"), + itemNames, i18n("Question"), + KStdGuiItem::del(), + TQString("multiple_delete_transfer")) + != KMessageBox::Continue) + return; // keep 'em + } + else + { + if (KMessageBox::warningContinueCancel(this, i18n("Are you sure you want to delete this transfer?"), + i18n("Question"), KStdGuiItem::del(), + TQString("delete_transfer")) + != KMessageBox::Continue) + return; + } + } + + // If we reach this, we want to delete all selected transfers + // Some of them might have finished in the meantime tho. Good that + // we used a TQGuardedPtr :) + + int transferFinishedMeanwhile = 0; + TQValueListConstIterator > lit = selectedItems.begin();; + while ( lit != selectedItems.end() ) + { + if ( *lit ) + (*lit)->slotRequestRemove(); + else + ++transferFinishedMeanwhile; + + ++lit; + } + + checkQueue(); // needed ! + + if ( !ksettings.b_expertMode && transferFinishedMeanwhile > 0 ) + KMessageBox::information(this, i18n("The transfer you wanted to delete completed before it could be deleted.", + "%n transfers you wanted to delete completed before they could be deleted.", + transferFinishedMeanwhile ), + TQString(), "completedBeforeDeletion" ); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::stopAll() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + log(i18n("Stopping all jobs"), false); + + TransferIterator it(myTransferList); + Transfer::TransferStatus Status; + for (; it.current(); ++it) { + Status = it.current()->getStatus(); + if (Status == Transfer::ST_TRYING || Status == Transfer::ST_RUNNING) + it.current()->slotStop(); + } + slotUpdateActions(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotQueueCurrent() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TransferIterator it(myTransferList); + + for (; it.current(); ++it) { + if (it.current()->isSelected()) { + it.current()->slotQueue(); + } + } + + // myTransferList->clearSelection(); + slotUpdateActions(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotTimerCurrent() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + + TransferIterator it(myTransferList); + + for (; it.current(); ++it) + if (it.current()->isSelected()) + it.current()->slotRequestSchedule(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif + +} + + +void TDEMainWidget::slotDelayCurrent() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TransferIterator it(myTransferList); + + for (; it.current(); ++it) + if (it.current()->isSelected()) + it.current()->slotRequestDelay(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotOpenTransfer() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TQString newtransfer; + bool ok = false; + +#ifdef _DEBUG + // newtransfer = "ftp://localhost/home/pch/test.gz"; + // newtransfer = "http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.18.tar.gz"; + newtransfer = "ftp://darkmoon/pub/test.gz"; +#endif + + while (!ok) { + newtransfer = KInputDialog::getText(i18n("Open Transfer"), i18n("Open transfer:"), newtransfer, &ok, this); + + // user presses cancel + if (!ok) { + return; + } + + KURL url = KURL::fromPathOrURL(newtransfer); + + if (!url.isValid()) { + KMessageBox::error(this, i18n("Malformed URL:\n%1").arg(newtransfer), i18n("Error")); + ok = false; + } + } + + addTransfer(newtransfer); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + + +void TDEMainWidget::slotCheckClipboard() +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + TQString clipData = TQApplication::clipboard()->text( TQClipboard::Clipboard ).stripWhiteSpace(); + + if (clipData != lastClipboard) { + sDebug << "New clipboard event" << endl; + + lastClipboard = clipData; + if ( lastClipboard.isEmpty() ) + return; + + KURL url = KURL::fromPathOrURL( lastClipboard ); + + if (url.isValid() && !url.isLocalFile()) + slotPasteTransfer(); + } + +#ifdef _DEBUG + //sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotPasteTransfer() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + TQString newtransfer; + + newtransfer = TQApplication::clipboard()->text(); + newtransfer = newtransfer.stripWhiteSpace(); + + if (!ksettings.b_expertMode) { + bool ok = false; + newtransfer = KInputDialog::getText(i18n("Open Transfer"), i18n("Open transfer:"), newtransfer, &ok, this); + + if (!ok) { + // cancelled +#ifdef _DEBUG + sDebugOut << endl; +#endif + return; + } + + } + + if (!newtransfer.isEmpty()) + addTransfer(newtransfer); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + +// destFile must be a filename, not a directory! And it will be deleted, if +// it exists already, without further notice. +void TDEMainWidget::addTransferEx(const KURL& url, const KURL& destFile) +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + if ( !sanityChecksSuccessful( url ) ) + return; + + KURL destURL = destFile; + + // Malformed destination url means one of two things. + // 1) The URL is empty. + // 2) The URL is only a filename, like a default (suggested) filename. + if ( !destURL.isValid() ) + { + // Setup destination + TQString destDir = getSaveDirectoryFor( url.fileName() ); + bool b_expertMode = ksettings.b_expertMode; + bool bDestisMalformed = true; + + while (bDestisMalformed) + { + if (!b_expertMode) { + // open the filedialog for confirmation + KFileDialog dlg( destDir, TQString(), + 0L, "save_as", true); + dlg.setCaption(i18n("Save As")); + dlg.setOperationMode(KFileDialog::Saving); + + // Use the destination name if not empty... + if (destURL.isEmpty()) + dlg.setSelection(url.fileName()); + else + dlg.setSelection(destURL.url()); + + if ( dlg.exec() == TQDialog::Rejected ) + { +#ifdef _DEBUG + sDebugOut << endl; +#endif + return; + } + else + { + destURL = dlg.selectedURL(); + ksettings.lastDirectory = destURL.directory(); + } + } + else { + // in expert mode don't open the filedialog + // if destURL is not empty, it's the suggested filename + destURL = KURL::fromPathOrURL( destDir + "/" + + ( destURL.isEmpty() ? + url.fileName() : destURL.url() )); + } + + //check if destination already exists + if(TDEIO::NetAccess::exists(destURL, false, this)) + { + if (KMessageBox::warningYesNo(this,i18n("Destination file \n%1\nalready exists.\nDo you want to overwrite it?").arg( destURL.prettyURL()), TQString(), i18n("Overwrite"), i18n("Do Not Overwrite") ) + == KMessageBox::Yes) + { + bDestisMalformed=false; + SafeDelete::deleteFile( destURL ); + } + else + { + b_expertMode=false; + ksettings.lastDirectory = destURL.directory(); + } + } + else + bDestisMalformed=false; + } + } + + else // destURL was given, check whether the file exists already + { + // simply delete it, the calling process should have asked if you + // really want to delete (at least tdehtml does) + if(TDEIO::NetAccess::exists(destURL, false, this)) + SafeDelete::deleteFile( destURL ); + } + + // create a new transfer item + Transfer *item = myTransferList->addTransfer(url, destURL); + KNotifyClient::event(kdock->winId(), "added", i18n("%1 has been added.").arg(url.prettyURL())); + item->updateAll(); // update the remaining fields + + if (ksettings.b_showIndividual) + item->showIndividual(); + + myTransferList->clearSelection(); + + checkQueue(); +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::addTransfers( const KURL::List& src, const TQString& destDir ) +{ + TQValueList urls_orig; + + for ( KURL::List::ConstIterator it = src.begin(); it != src.end(); ++it ) + { + KURLPair url; + url.src = *it; + if ( url.src.fileName().endsWith( ".kgt" ) ) + readTransfersEx(url.src); + else + urls_orig.append( url ); + } + + if ( urls_orig.isEmpty() ) + return; + + if ( urls_orig.count() == 1 ) // just one file -> ask for filename + { + KURL destFile; + + if ( !destDir.isEmpty() ) + { + // create a proper destination file from destDir + KURL destURL = KURL::fromPathOrURL( destDir ); + TQString fileName = urls_orig.first().src.fileName(); + + // in case the fileName is empty, we simply ask for a filename in + // addTransferEx. Do NOT attempt to use an empty filename, that + // would be a directory (and we don't want to overwrite that!) + if ( !fileName.isEmpty() ) + { + destURL.adjustPath( +1 ); + destURL.setFileName( fileName ); + if(TDEIO::NetAccess::exists(destURL, false, this)) + { + if (KMessageBox::warningYesNo(this,i18n("Destination file \n%1\nalready exists.\nDo you want to overwrite it?").arg( destURL.prettyURL()), TQString(), i18n("Overwrite"), i18n("Do Not Overwrite") ) + == KMessageBox::Yes) + { + SafeDelete::deleteFile( destURL ); + destFile = destURL; + } + } + else + { + destFile = destURL; + } + } + } + + addTransferEx( urls_orig.first().src, destFile ); + return; + } + + // multiple files -> ask for directory, not for every single filename + + bool dir_accepted = false; + TQValueList::Iterator it; + TQValueList urls; + KURL::List urlsToDelete; + while ( !dir_accepted ) + { + urlsToDelete.clear(); + urls = urls_orig; // copy the list here, urls might be changed, yet when we return here (Cancel), + // we want to start again with the original list + dir_accepted = true; //Set to false later when Cancel is pressed + KURL dest; + if ( destDir.isEmpty() || !TQFileInfo( destDir ).isDir() ) + { + if ( !destDir.isEmpty() ) + dest.setPath( destDir ); + else + dest.setPath( getSaveDirectoryFor( src.first().fileName() ) ); + + // ask in any case, when destDir is empty + if ( destDir.isEmpty() || !TQFileInfo( dest.path() ).isDir() ) + { + TQString dir = KFileDialog::getExistingDirectory( dest.path() ); + if ( dir.isEmpty() ) // aborted + return; + + dest.setPath( dir ); + ksettings.lastDirectory = dir; + } + } + + // dest is now finally the real destination directory for all the files + dest.adjustPath(+1); + + // create new transfer items + bool skip_all = false; + bool overwrite_all = false; + it = urls.begin(); + TDEIO::RenameDlg_Result result; + while ( it != urls.end() ) + { + + if ( !sanityChecksSuccessful( (*it).src ) ) + { + it = urls.erase( it ); + continue; // shouldn't we notify the user?? + } + + (*it).dest = dest; + TQString fileName = (*it).src.fileName(); + if ( fileName.isEmpty() ) // simply use the full url as filename + fileName = KURL::encode_string_no_slash( (*it).src.prettyURL() ); + + (*it).dest.setFileName( fileName ); + + if( TDEIO::NetAccess::exists((*it).dest, false, this)) + { + TQString newdest; + if (skip_all) + result = TDEIO::R_SKIP; + else if( overwrite_all ) + result = TDEIO::R_OVERWRITE; + else + { + TQFileInfo finfo( (*it).dest.path() ); + TQString caption = i18n( "File Already exists" ) + " - KGet"; + result = TDEIO::open_RenameDlg( caption, (*it).src.url(), (*it).dest.url(), TDEIO::RenameDlg_Mode(TDEIO::M_OVERWRITE|TDEIO::M_SKIP|TDEIO::M_MULTI), newdest, (TDEIO::filesize_t) -1, (TDEIO::filesize_t)finfo.size(), (time_t) -1, (time_t) -1, (time_t) -1, finfo.lastModified().toTime_t()); + } + switch (result) + { + case TDEIO::R_RENAME: + (*it).dest = KURL::fromPathOrURL( newdest ); + break; + case TDEIO::R_OVERWRITE_ALL: + overwrite_all = true; //fall through + case TDEIO::R_OVERWRITE: + urlsToDelete.append( (*it).dest ); + break; + case TDEIO::R_AUTO_SKIP: + skip_all = true; + case TDEIO::R_SKIP: //fall through + it = urls.erase( it ); + continue; + break; + default: // Cancel, ask again for directory + dir_accepted = false; + } + if ( !dir_accepted ) + break; + } // if(TDEIO::NetAccess::exists + ++it; + } // while ( it != urls.end() ) + } // while ( !dir_accepted ) + + KURL::List::Iterator it_1 = urlsToDelete.begin(); + for ( ; it_1 != urlsToDelete.end(); ++it_1 ) + { + SafeDelete::deleteFile( *it_1 ); + } + + int numdl = 0; + it = urls.begin(); + for ( ; it != urls.end(); ++it ) + { + Transfer *item = myTransferList->addTransfer((*it).src, (*it).dest); + item->updateAll(); // update the remaining fields + numdl++; + } + + KNotifyClient::event(kdock->winId(), "added", i18n("1 download has been added.", "%n downloads have been added.", numdl)); + + myTransferList->clearSelection(); + + checkQueue(); +} + +void TDEMainWidget::addTransfer(const TQString& src) +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + if ( src.isEmpty() ) + return; + + addTransferEx( KURL::fromPathOrURL( src ) ); + +#ifdef _DEBUG + sDebugOut << endl; +#endif + +} + + +void TDEMainWidget::checkQueue() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + uint numRun = 0; + int status; + Transfer *item; + TransferIterator it(myTransferList); + + if (!ksettings.b_offline) { + + // count running transfers + for (; it.current(); ++it) { + status = it.current()->getStatus(); + if (status == Transfer::ST_RUNNING || status == Transfer::ST_TRYING) + numRun++; + } + sDebug << "Found " << numRun << " Running Jobs" << endl; + it.reset(); + bool isRunning; + bool isQuequed; + for (; it.current() && numRun < ksettings.maxSimultaneousConnections; ++it) { + item = it.current(); + isRunning = (item->getStatus() == Transfer::ST_RUNNING) || ((item->getStatus() == Transfer::ST_TRYING)); + + isQuequed = (item->getMode() == Transfer::MD_QUEUED || item->getMode() == Transfer::MD_NEW); + + if (!isRunning && isQuequed && !ksettings.b_offline) + { + log(i18n("Starting another queued job.")); + item->slotResume(); + numRun++; + } + } + + slotUpdateActions(); + + updateStatusBar(); + +// } else {//TODO this has to be solved different +// log(i18n("Cannot continue offline status")); + } + + it.reset(); + for (; it.current(); ++it) + { + item = it.current(); + if (item->getMode() == Transfer::MD_NEW && item->getStatus() == Transfer::ST_STOPPED) + { + item->checkCache(); + } + } +#ifdef _DEBUG + sDebugOut << endl; +#endif + +} + + +void TDEMainWidget::slotAnimTimeout() +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + bool isTransfer; + + animCounter++; + if (animCounter == myTransferList->getPhasesNum()) { + //updateStatusBar(); + animCounter = 0; + } + // update status of all items of transferList + isTransfer = myTransferList->updateStatus(animCounter); + + //if (this->isVisible()) { + updateStatusBar(); + //} +#ifdef _DEBUG + //sDebugOut << endl; +#endif + +} + + +void TDEMainWidget::slotTransferTimeout() +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + Transfer *item; + TransferIterator it(myTransferList); + + bool flag = false; + + for (; it.current(); ++it) { + item = it.current(); + if (item->getMode() == Transfer::MD_SCHEDULED && item->getStartTime() <= TQDateTime::currentDateTime()) { + item->setMode(Transfer::MD_QUEUED); + flag = true; + } + } + + if (flag) { + checkQueue(); + } + + if (ksettings.b_autoDisconnect && ksettings.b_timedDisconnect && ksettings.disconnectTime <= TQTime::currentTime() && ksettings.disconnectDate == TQDate::currentDate()) { + onlineDisconnect(); + } + +#ifdef _DEBUG + //sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotAutosaveTimeout() +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + writeTransfers(); + +#ifdef _DEBUG + //sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotStatusChanged(Transfer * item, int _operation) +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + switch (_operation) { + + case Transfer::OP_FINISHED: + { + TQString srcurl = item->getSrc().prettyURL(); + if (ksettings.b_removeOnSuccess && !item->keepDialogOpen() ) + { + delete item; + item = 0L; + } + else + item->setMode(Transfer::MD_NONE); + + if (!myTransferList->areTransfersQueuedOrScheduled()) { + // no items or only delayed and finished items in the TransferList + if (ksettings.b_autoDisconnect) + onlineDisconnect(); + + if (ksettings.b_autoShutdown) { + slotQuit(); + return; + } + KNotifyClient::event(kdock->winId(), "finishedall", i18n("All the downloads are finished.")); + } + else + { + KNotifyClient::event(kdock->winId(), "finished", i18n("%1 successfully downloaded.").arg(srcurl)); + } + + if ( item ) + item->slotUpdateActions(); + + break; + } + case Transfer::OP_RESUMED: + slotUpdateActions(); + item->slotUpdateActions(); + // play(ksettings.audioStarted); + break; + case Transfer::OP_PAUSED: + break; + case Transfer::OP_REMOVED: + delete item; + return; // checkQueue() will be called only once after all deletions + + case Transfer::OP_ABORTED: + break; + case Transfer::OP_DELAYED: + case Transfer::OP_QUEUED: + slotUpdateActions(); + item->slotUpdateActions(); + break; + case Transfer::OP_SCHEDULED: + slotUpdateActions(); + item->slotUpdateActions(); + slotTransferTimeout(); // this will check schedule times + return; // checkQueue() is called from slotTransferTimeout() + } + checkQueue(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::dragEnterEvent(TQDragEnterEvent * event) +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + event->accept(KURLDrag::canDecode(event) || TQTextDrag::canDecode(event)); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::dropEvent(TQDropEvent * event) +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + KURL::List list; + TQString str; + + if (KURLDrag::decode(event, list)) { + addTransfers(list); + } else if (TQTextDrag::decode(event, str)) { + addTransfer(str); + } + sDebugOut << endl; +} + + +void TDEMainWidget::slotCopyToClipboard() +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + Transfer *item = (Transfer *) myTransferList->currentItem(); + + if (item) { + TQString url = item->getSrc().url(); + TQClipboard *cb = TQApplication::clipboard(); + cb->setText( url, TQClipboard::Selection ); + cb->setText( url, TQClipboard::Clipboard); + myTransferList->clearSelection(); + } + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotMoveToBegin() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + myTransferList->moveToBegin((Transfer *) myTransferList->currentItem()); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotMoveToEnd() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + myTransferList->moveToEnd((Transfer *) myTransferList->currentItem()); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotOpenIndividual() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + Transfer *item = (Transfer *) myTransferList->currentItem(); + if (item) + item->showIndividual(); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + +bool TDEMainWidget::queryClose() +{ + if( kapp->sessionSaving()) + return true; + hide(); + return false; +} + +void TDEMainWidget::setAutoSave() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + autosaveTimer->stop(); + if (ksettings.b_autoSave) { + autosaveTimer->start(ksettings.autoSaveInterval * 60000); + } + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + + +void TDEMainWidget::setAutoDisconnect() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + // disable action when we are connected permanently + m_paAutoDisconnect->setEnabled(ksettings.connectionType != PERMANENT); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + +void TDEMainWidget::slotPreferences() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + if ( !prefDlg ) + prefDlg = new DlgPreferences(this); + + prefDlg->show(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + +void TDEMainWidget::slotConfigureNotifications() +{ + KNotifyDialog::configure(this); +} + +void TDEMainWidget::slotToggleLogWindow() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + b_viewLogWindow = !b_viewLogWindow; + if (b_viewLogWindow) + logWindow->show(); + else + logWindow->hide(); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotToggleAnimation() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + ksettings.b_useAnimation = !ksettings.b_useAnimation; + + if (!ksettings.b_useAnimation && animTimer->isActive()) { + animTimer->stop(); + animTimer->start(1000); + animCounter = 0; + } else { + animTimer->stop(); + animTimer->start(400); + } + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + +void TDEMainWidget::slotToggleOfflineMode() +{ +#ifdef _DEBUG + sDebugIn "ksettings.b_offlineMode = " << ksettings.b_offlineMode << endl; +#endif + + ksettings.b_offlineMode = !ksettings.b_offlineMode; + ksettings.b_offline=(ksettings.b_offlineMode || !b_connected); + if (ksettings.b_offline) { + log(i18n("Offline mode on.")); + stopAll(); + setCaption(i18n("Offline"), false); + m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_off")); + } else { + log(i18n("Offline mode off.")); + setCaption(TQString(), false); + m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_on")); + } + + m_paOfflineMode->setChecked(ksettings.b_offline); + + + slotUpdateActions(); + checkQueue(); +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotToggleExpertMode() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + ksettings.b_expertMode = !ksettings.b_expertMode; + + if (ksettings.b_expertMode) { + log(i18n("Expert mode on.")); + } else { + log(i18n("Expert mode off.")); + } + m_paExpertMode->setChecked(ksettings.b_expertMode); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotToggleUseLastDir() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + ksettings.b_useLastDir = !ksettings.b_useLastDir; + + if (ksettings.b_useLastDir) { + log(i18n("Use last folder on.")); + } else { + log(i18n("Use last folder off.")); + } + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotToggleAutoDisconnect() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + ksettings.b_autoDisconnect = !ksettings.b_autoDisconnect; + + if (ksettings.b_autoDisconnect) { + log(i18n("Auto disconnect on.")); + } else { + log(i18n("Auto disconnect off.")); + } + m_paAutoDisconnect->setChecked(ksettings.b_autoDisconnect); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotToggleAutoShutdown() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + ksettings.b_autoShutdown = !ksettings.b_autoShutdown; + + if (ksettings.b_autoShutdown) { + log(i18n("Auto shutdown on.")); + } else { + log(i18n("Auto shutdown off.")); + } + + m_paAutoShutdown->setChecked(ksettings.b_autoShutdown); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotToggleAutoPaste() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + ksettings.b_autoPaste = !ksettings.b_autoPaste; + + if (ksettings.b_autoPaste) { + log(i18n("Auto paste on.")); + clipboardTimer->start(1000); + } else { + log(i18n("Auto paste off.")); + clipboardTimer->stop(); + } + m_paAutoPaste->setChecked(ksettings.b_autoPaste); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotToggleDropTarget() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + m_showDropTarget = !m_showDropTarget; + + if (m_showDropTarget) { + kdrop->show(); + kdrop->updateStickyState(); + m_paDropTarget->setText(i18n("Hide Drop &Target")); + } + else { + kdrop->hide(); + m_paDropTarget->setText(i18n("Show Drop &Target")); + } + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotKonquerorIntegration() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + bool bIsKonquiEnable=!ksettings.b_KonquerorIntegration; + ksettings.b_KonquerorIntegration=!ksettings.b_KonquerorIntegration; + TDEConfig cfg("konquerorrc", false, false); + cfg.setGroup("HTML Settings"); + cfg.writePathEntry("DownloadManager",TQString((bIsKonquiEnable)?"kget":"")); + cfg.sync(); + if (bIsKonquiEnable) + { + m_paKonquerorIntegration->setText(i18n("Disable &KGet as Konqueror Download Manager")); + } + else + { + m_paKonquerorIntegration->setText(i18n("Enable &KGet as Konqueror Download Manager")); + } + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotPopupMenu(Transfer * item) +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + // select current item + myTransferList->setCurrentItem(item); + + // set action properties + slotUpdateActions(); + + // popup transfer menu at the position + TQWidget *menu = guiFactory()->container("transfer",this); + ((TQPopupMenu *) menu)->popup(TQCursor::pos()); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::setListFont() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + myTransferList->setFont(ksettings.listViewFont); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + +void TDEMainWidget::slotUpdateActions() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + + // disable all signals + m_paQueue->blockSignals(true); + m_paTimer->blockSignals(true); + m_paDelay->blockSignals(true); + + // at first turn off all buttons like when nothing is selected + m_paQueue->setChecked(false); + m_paTimer->setChecked(false); + m_paDelay->setChecked(false); + + m_paQueue->setEnabled(false); + m_paTimer->setEnabled(false); + m_paDelay->setEnabled(false); + + m_paDelete->setEnabled(false); + m_paResume->setEnabled(false); + m_paPause->setEnabled(false); + m_paRestart->setEnabled(false); + + m_paCopy->setEnabled(false); + m_paIndividual->setEnabled(false); + m_paMoveToBegin->setEnabled(false); + m_paMoveToEnd->setEnabled(false); + + Transfer *item; + Transfer *first_item = 0L; + TransferIterator it(myTransferList); + int index = 0; + int totals_items = 0; + int sel_items = 0; + + for (; it.current(); ++it, ++totals_items) { + + // update action on visibles windows + if (it.current()->isVisible()) + it.current()->slotUpdateActions(); + + if (it.current()->isSelected()) { + item = it.current(); + sel_items = totals_items; + index++; // counting number of selected items + if (index == 1) { + first_item = item; // store first selected item + if (totals_items > 0) + m_paMoveToBegin->setEnabled(true); + + m_paMoveToEnd->setEnabled(true); + } else { + + m_paMoveToBegin->setEnabled(false); + m_paMoveToEnd->setEnabled(false); + } + // enable PAUSE, RESUME and RESTART only when we are online and not in offline mode +#ifdef _DEBUG + sDebug << "-->ONLINE= " << ksettings.b_offline << endl; +#endif + if (item == first_item && !ksettings.b_offline) { + switch (item->getStatus()) { + case Transfer::ST_TRYING: + case Transfer::ST_RUNNING: + m_paResume->setEnabled(false); + m_paPause->setEnabled(true); + m_paRestart->setEnabled(true); + break; + case Transfer::ST_STOPPED: + m_paResume->setEnabled(true); + m_paPause->setEnabled(false); + m_paRestart->setEnabled(false); +#ifdef _DEBUG + sDebug << "STATUS IS stopped" << item->getStatus() << endl; +#endif + break; + case Transfer::ST_FINISHED: + m_paResume->setEnabled(false); + m_paPause->setEnabled(false); + m_paRestart->setEnabled(false); + break; + + + } //end switch + + } else if (item->getStatus() != first_item->getStatus()) { + // disable all when all selected items don't have the same status + m_paResume->setEnabled(false); + m_paPause->setEnabled(false); + m_paRestart->setEnabled(false); + } + + + if (item == first_item) { + m_paDelete->setEnabled(true); + m_paCopy->setEnabled(true); + m_paIndividual->setEnabled(true); + if (item->getStatus() != Transfer::ST_FINISHED) { + m_paQueue->setEnabled(true); + m_paTimer->setEnabled(true); + m_paDelay->setEnabled(true); + + switch (item->getMode()) { + case Transfer::MD_QUEUED: +#ifdef _DEBUG + sDebug << "....................THE MODE IS MD_QUEUED " << item->getMode() << endl; +#endif + m_paQueue->setChecked(true); + break; + case Transfer::MD_SCHEDULED: +#ifdef _DEBUG + sDebug << "....................THE MODE IS MD_SCHEDULED " << item->getMode() << endl; +#endif + m_paTimer->setChecked(true); + break; + case Transfer::MD_DELAYED: +#ifdef _DEBUG + sDebug << "....................THE MODE IS MD_DELAYED " << item->getMode() << endl; +#endif + m_paDelay->setChecked(true); + break; + } + } + } else if (item->getMode() != first_item->getMode()) { + // unset all when all selected items don't have the same mode + m_paQueue->setChecked(false); + m_paTimer->setChecked(false); + m_paDelay->setChecked(false); + m_paMoveToBegin->setEnabled(false); + m_paMoveToEnd->setEnabled(false); + m_paQueue->setEnabled(false); + m_paTimer->setEnabled(false); + m_paDelay->setEnabled(false); + } + + } // when item is selected + } // loop + + + + if (sel_items == totals_items - 1) + m_paMoveToEnd->setEnabled(false); + + // enable all signals + + + + m_paQueue->blockSignals(false); + m_paTimer->blockSignals(false); + m_paDelay->blockSignals(false); + + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::updateStatusBar() +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + Transfer *item; + TQString tmpstr; + + int totalFiles = 0; + TDEIO::filesize_t totalSize = 0; + int totalSpeed = 0; + unsigned int remTime = 0; + + TransferIterator it(myTransferList); + + for (; it.current(); ++it) { + item = it.current(); + if (item->getTotalSize() != 0) { + totalSize += (item->getTotalSize() - item->getProcessedSize()); + } + totalFiles++; + totalSpeed += item->getSpeed(); + + if (item->getRemainingTime() > remTime) { + remTime = item->getRemainingTime(); + } + } + + statusBar()->changeItem(i18n(" Transfers: %1 ").arg(myTransferList->childCount()), ID_TOTAL_TRANSFERS); + statusBar()->changeItem(i18n(" Files: %1 ").arg(totalFiles), ID_TOTAL_FILES); + statusBar()->changeItem(i18n(" Size: %1 ").arg(TDEIO::convertSize(totalSize)), ID_TOTAL_SIZE); + statusBar()->changeItem(i18n(" Time: %1 ").arg(TDEIO::convertSeconds(remTime)), ID_TOTAL_TIME); + statusBar()->changeItem(i18n(" %1/s ").arg(TDEIO::convertSize(totalSpeed)), ID_TOTAL_SPEED); + //update size for each statusbar field + statusBar()->setItemFixed(ID_TOTAL_TRANSFERS, -1); + statusBar()->setItemFixed(ID_TOTAL_FILES, -1); + statusBar()->setItemFixed(ID_TOTAL_SIZE, -1); + statusBar()->setItemFixed(ID_TOTAL_TIME, -1); + statusBar()->setItemFixed(ID_TOTAL_SPEED, -1); + + if (kdock) { + tmpstr = i18n("Transfers: %1 ").arg(myTransferList->childCount()) + + i18n("
Files: %1 ").arg(totalFiles) + + i18n("
Size: %1 ").arg(TDEIO::convertSize(totalSize)) + + i18n("
Time: %1 ").arg(TDEIO::convertSeconds(remTime)) + + i18n("
Speed: %1/s").arg(TDEIO::convertSize(totalSpeed)); + kdock->updateToolTip( tmpstr ); + //trayicon changes if download is in progress + if (totalSpeed == 0) + { + kdock->changeIcon( "kget_dock" ); + } + else + { + kdock->changeIcon( "kget_dock_download" ); + } + } +#ifdef _DEBUG + //sDebugOut << endl; +#endif +} + + +void TDEMainWidget::onlineDisconnect() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + if (!b_connected) { + return; + } + + if (!ksettings.b_expertMode) { + if (KMessageBox::questionYesNo(this, i18n("Do you really want to disconnect?"), + i18n("Question"), + i18n("Disconnect"), i18n("Stay Connected"), + "kget_AutoOnlineDisconnect") + != KMessageBox::Yes) { + return; + } + } + log(i18n("Disconnecting...")); + system(TQFile::encodeName(ksettings.disconnectCommand)); + +#ifdef _DEBUG + sDebugOut << endl; +#endif +} + + +void TDEMainWidget::slotCheckConnection() +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + bool old = b_connected; + checkOnline(); + if (b_connected != old) { + if (b_connected) { + log(i18n("We are online.")); + setCaption(TQString(), false); + ksettings.b_offline=ksettings.b_offlineMode; + checkQueue(); + } else { + log(i18n("We are offline.")); + setCaption(i18n("Offline"), false); + ksettings.b_offline=true; + stopAll(); + } + } +#ifdef _DEBUG + //sDebugOut << endl; +#endif +} + + +void TDEMainWidget::checkOnline() +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifreq)); + + // setup the device name according to the type of connection and link number + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", ConnectionDevices[ksettings.connectionType].ascii(), ksettings.linkNumber); + + bool flag = false; + + if (ksettings.connectionType != PERMANENT) { + // get the flags for particular device + if (ioctl(_sock, SIOCGIFFLAGS, &ifr) < 0) { + flag = true; + b_connected = false; + } else if (ifr.ifr_flags == 0) { +#ifdef _DEBUG + sDebug << "Can't get flags from interface " << ifr.ifr_name << endl; +#endif + b_connected = false; + } else if (ifr.ifr_flags & IFF_UP) { // if (ifr.ifr_flags & IFF_RUNNING) + b_connected = true; + } else { + b_connected = false; + } + } else { + b_connected = true; // PERMANENT connection + } + + m_paOfflineMode->setEnabled(b_connected); + + if (flag) { +#ifdef _DEBUG + sDebug << "Unknown interface " << ifr.ifr_name << endl; +#endif + } +#ifdef _DEBUG + //sDebugOut << endl; +#endif +} + + +// Helper method for opening device socket + + + + +static int sockets_open() +{ +#ifdef _DEBUG + sDebugIn << endl; +#endif + + inet_sock = socket(AF_INET, SOCK_DGRAM, 0); +#ifdef AF_IPX + ipx_sock = socket(AF_IPX, SOCK_DGRAM, 0); +#else + ipx_sock = -1; +#endif + +#ifdef AF_AX25 + ax25_sock = socket(AF_AX25, SOCK_DGRAM, 0); +#else + ax25_sock = -1; +#endif + + ddp_sock = socket(AF_APPLETALK, SOCK_DGRAM, 0); + /* + * Now pick any (exisiting) useful socket family for generic queries + */ + + sDebug << "<<< sockets_open () " << endl; + if (inet_sock != -1) + return inet_sock; + if (ipx_sock != -1) + return ipx_sock; + if (ax25_sock != -1) + return ax25_sock; + /* + * If this is -1 we have no known network layers and its time to jump. + */ + +#ifdef _DEBUG + sDebugOut << endl; +#endif + + return ddp_sock; +} + + +/** No descriptions */ +void TDEMainWidget::customEvent(TQCustomEvent * _e) +{ +#ifdef _DEBUG + //sDebugIn << endl; +#endif + + + SlaveEvent *e = (SlaveEvent *) _e; + unsigned int result = e->getEvent(); + + switch (result) { + + // running cases.. + case Slave::SLV_PROGRESS_SIZE: + e->getItem()->slotProcessedSize(e->getData()); + break; + case Slave::SLV_PROGRESS_SPEED: + e->getItem()->slotSpeed(e->getData()); + break; + + case Slave::SLV_RESUMED: + e->getItem()->slotExecResume(); + break; + + // stopping cases + case Slave::SLV_FINISHED: + e->getItem()->slotFinished(); + break; + case Slave::SLV_PAUSED: + e->getItem()->slotExecPause(); + break; + case Slave::SLV_SCHEDULED: + e->getItem()->slotExecSchedule(); + break; + + case Slave::SLV_DELAYED: + e->getItem()->slotExecDelay(); + break; + case Slave::SLV_CONNECTED: + e->getItem()->slotExecConnected(); + break; + + case Slave::SLV_CAN_RESUME: + e->getItem()->slotCanResume((bool) e->getData()); + break; + + case Slave::SLV_TOTAL_SIZE: + e->getItem()->slotTotalSize(e->getData()); + break; + + case Slave::SLV_ERROR: + e->getItem()->slotExecError(); + break; + + case Slave::SLV_BROKEN: + e->getItem()->slotExecBroken(); + break; + + case Slave::SLV_REMOVED: + e->getItem()->slotExecRemove(); + break; + + case Slave::SLV_INFO: + e->getItem()->logMessage(e->getMsg()); + break; + + case Slave::SLV_NOTINCACHE: + e->getItem()->NotInCache(); + break; + default: +#ifdef _DEBUG + sDebug << "Unknown Result..die" << result << endl; +#endif + assert(0); + } + + +#ifdef _DEBUG + //sDebugOut << endl; +#endif +} + +TQString TDEMainWidget::getSaveDirectoryFor( const TQString& filename ) const +{ + // first set destination directory to current directory ( which is also last used ) + TQString destDir = ksettings.lastDirectory; + + if (!ksettings.b_useLastDir) { + // check wildcards for default directory + DirList::Iterator it; + for (it = ksettings.defaultDirList.begin(); it != ksettings.defaultDirList.end(); ++it) { + TQRegExp rexp((*it).extRegexp); + + rexp.setWildcard(true); + + if ((rexp.search( filename )) != -1) { + destDir = (*it).defaultDir; + break; + } + } + } + + return destDir; +} + +bool TDEMainWidget::sanityChecksSuccessful( const KURL& url ) +{ + if (!url.isValid() || !KProtocolInfo::supportsReading( url ) ) + { + if (!ksettings.b_expertMode) + KMessageBox::error(this, i18n("Malformed URL:\n%1").arg(url.prettyURL()), i18n("Error")); + + return false; + } + // if we find this URL in the list + Transfer *transfer = myTransferList->find( url ); + if ( transfer ) + { + if ( transfer->getStatus() != Transfer::ST_FINISHED ) + { + if ( !ksettings.b_expertMode ) + { + KMessageBox::error(this, i18n("Already saving URL\n%1").arg(url.prettyURL()), i18n("Error")); + } + + transfer->showIndividual(); + return false; + } + + else // transfer is finished, ask if we want to download again + { + if ( ksettings.b_expertMode || + (KMessageBox::questionYesNo(this, i18n("Already saved URL\n%1\nDownload again?").arg(url.prettyURL()),i18n("Question"),i18n("Download Again"),KStdGuiItem::cancel() ) + == KMessageBox::Yes) ) + { + transfer->slotRequestRemove(); + checkQueue(); + return true; + } + } + + return false; + } + + // why restrict this to ftp and http? (pfeiffer) +// // don't download file URL's TODO : uncomment? +// if (url.protocol() == "http" && url.protocol() != "ftp") { +// KMessageBox::error(this, i18n("File protocol not accepted!\n%1").arg(url.prettyURL()), i18n("Error")); +// #ifdef _DEBUG +// sDebugOut << endl; +// #endif +// return false; +// } + + return true; +} + +bool TDEMainWidget::isDropTargetVisible() const +{ + return m_showDropTarget; +} + +void TDEMainWidget::setDropTargetVisible( bool setVisible ) +{ + if ( setVisible != isDropTargetVisible() ) + { + m_paDropTarget->activate(); + } +} + +void TDEMainWidget::setOfflineMode( bool offline ) +{ + if ( ksettings.b_offlineMode != offline ) + slotToggleOfflineMode(); +} + +bool TDEMainWidget::isOfflineMode() const +{ + return ksettings.b_offlineMode; +} + +void TDEMainWidget::activateDropTarget() +{ + setDropTargetVisible( true ); +} + +void TDEMainWidget::slotShowMenubar() +{ + if(m_menubarAction->isChecked()) + menuBar()->show(); + else + menuBar()->hide(); +} + +#include "kmainwidget.moc" diff --git a/kget/tdemainwidget.h b/kget/tdemainwidget.h new file mode 100644 index 00000000..cd2ce92d --- /dev/null +++ b/kget/tdemainwidget.h @@ -0,0 +1,233 @@ +/*************************************************************************** +* kmainwidget.h +* ------------------- +* +* Revision : $Id$ +* begin : Tue Jan 29 2002 +* copyright : (C) 2002 by Patrick Charbonnier +* : Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss +* email : pch@freeshell.org +* +****************************************************************************/ + +/*************************************************************************** + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + ***************************************************************************/ + + +#ifndef _KMAINWIDGET_H_ +#define _KMAINWIDGET_H_ + +#include +#include +#include +#include "common.h" + +#include "kget_iface.h" + +class TDEAction; +//class TDEToggleAction; +class TDERadioAction; + +class DockWidget; +class DropTarget; +class LogWindow; +class DlgPreferences; + +class Transfer; +class TransferList; +class Settings; + + +class TDEMainWidget:public TDEMainWindow, virtual public KGetIface +{ + + Q_OBJECT + + +public: + enum StatusbarFields { ID_TOTAL_TRANSFERS = 1, ID_TOTAL_FILES, ID_TOTAL_SIZE, + ID_TOTAL_TIME , ID_TOTAL_SPEED }; + + TDEMainWidget(bool bShowMain = false); + ~TDEMainWidget(); + + void addTransfer( const TQString& src ); + void addTransferEx( const KURL& url, + const KURL& destFile = KURL()); + + // dcop interface + virtual void addTransfers( const KURL::List& src, const TQString& destDir = TQString() ); + virtual bool isDropTargetVisible() const; + virtual void setDropTargetVisible( bool setVisible ); + + + void checkQueue(); + + void setListFont(); + void setAutoSave(); + void setAutoDisconnect(); + + LogWindow *logwin()const { return logWindow;} + friend class Settings; + + // Actions + TDEToggleAction *m_paShowLog; + TDEToggleAction *m_menubarAction; + TDEAction *m_paPreferences; + TDEAction *m_paQuit; + bool b_viewLogWindow; + + void readTransfersEx(const KURL & url); + + void activateDropTarget(); + +public slots: + void slotPasteTransfer(); + void slotToggleLogWindow(); + void slotPreferences(); + void slotConfigureNotifications(); + void slotToggleExpertMode(); + void slotToggleOfflineMode(); + void slotToggleUseLastDir(); + void slotToggleAutoDisconnect(); + void slotToggleAutoShutdown(); + void slotToggleAutoPaste(); + void slotToggleDropTarget(); + void slotToggleAnimation(); + void slotUpdateActions(); + void slotKonquerorIntegration(); + +protected slots: + void slotQuit(); + + void slotOpenTransfer(); + void slotExportTransfers(); + void slotImportTransfers(); + void slotImportTextFile(); + + void slotSaveYourself(); + void slotCheckConnection(); + + + void slotStatusChanged(Transfer * item, int _operation); + + void slotResumeCurrent(); + void slotPauseCurrent(); + void slotDeleteCurrent(); + void slotRestartCurrent(); + + void slotQueueCurrent(); + void slotTimerCurrent(); + void slotDelayCurrent(); + + void slotOpenIndividual(); + + void slotAnimTimeout(); + void slotTransferTimeout(); + void slotAutosaveTimeout(); + + void slotMoveToBegin(); + void slotMoveToEnd(); + + void slotCopyToClipboard(); + void slotCheckClipboard(); + + void slotConfigureToolbars(); + void slotNewToolbarConfig(); + void slotShowMenubar(); + + void slotPopupMenu(Transfer * item); + +protected: + virtual void setOfflineMode( bool online ); + virtual bool isOfflineMode() const; + virtual bool queryClose(); + void writeLog(); + + // drag and drop + virtual void dragEnterEvent(TQDragEnterEvent *); + virtual void dropEvent(TQDropEvent *); + + void readTransfers(bool ask_for_name = false); + void writeTransfers(bool ask_for_name = false); + + + void setupGUI(); + void setupWhatsThis(); + + void updateStatusBar(); + + // some flags + bool b_connected; + bool b_viewPreferences; + + // utility functions + void onlineDisconnect(); + void checkOnline(); + void stopAll(); + void log(const TQString & message, bool statusbar = true); + + /** No descriptions */ + virtual void customEvent(TQCustomEvent * e); + + // various timers + TQTimer *animTimer; // animation timer + TQTimer *connectionTimer; // timer that checks whether we are online + TQTimer *transferTimer; // timer for scheduled transfers + TQTimer *autosaveTimer; // timer for autosaving transfer list + TQTimer *clipboardTimer; // timer for checking clipboard - autopaste function + + TQString logFileName; + + + +private: + TQString getSaveDirectoryFor( const TQString& filename ) const; + bool sanityChecksSuccessful( const KURL& url ); + + TransferList * myTransferList; + KHelpMenu *menuHelp; + + LogWindow *logWindow; + DlgPreferences *prefDlg; + DockWidget *kdock; + + TQString lastClipboard; + + uint animCounter; + + int _sock; + + // Actions + TDEAction *m_paOpenTransfer, *m_paPasteTransfer, *m_paExportTransfers, *m_paImportTransfers; + TDEAction *m_paImportText; + + TDEAction *m_paMoveToBegin, *m_paMoveToEnd, *m_paCopy, *m_paIndividual; + TDEAction *m_paResume, *m_paPause, *m_paDelete, *m_paRestart; + TDERadioAction *m_paQueue, *m_paTimer, *m_paDelay; + + TDEToggleAction *m_paUseAnimation; + TDEToggleAction *m_paExpertMode, *m_paUseLastDir, *m_paOfflineMode; + TDEToggleAction *m_paAutoDisconnect, *m_paAutoShutdown, *m_paAutoPaste; + + TDEAction *m_paDropTarget; + TDEAction *m_paKonquerorIntegration; + bool m_showDropTarget; + +}; + +extern TDEMainWidget *kmain; +extern DropTarget *kdrop; + +#endif // _KMAINWIDGET_H_ diff --git a/kopete/libkopete/kopeteblacklister.cpp b/kopete/libkopete/kopeteblacklister.cpp deleted file mode 100644 index e249d736..00000000 --- a/kopete/libkopete/kopeteblacklister.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - kopeteblacklister.cpp - Kopete BlackLister - - Copyright (c) 2004 by Roie Kerstein - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#include "kopeteblacklister.h" - -#include "kopetecontact.h" - -#include -#include - -#include - -namespace Kopete -{ - -class BlackLister::Private -{ -public: - TQStringList blacklist; - TQString owner; - TQString protocol; -}; - - -BlackLister::BlackLister(const TQString &protocolId, const TQString &accountId, TQObject *parent, const char *name) - : TQObject(parent, name), d( new Private ) -{ - TDEConfig *config = TDEGlobal::config(); - - d->owner = accountId; - d->protocol = protocolId; - config->setGroup("BlackLister"); - d->blacklist = config->readListEntry( d->protocol + TQString::fromLatin1("_") + d->owner ); -} - -BlackLister::~BlackLister() -{ - delete d; -} - - -bool BlackLister::isBlocked(const TQString &contactId) -{ - return (d->blacklist.find( contactId ) != d->blacklist.end() ); -} - -bool BlackLister::isBlocked(Contact *contact) -{ - return isBlocked(contact->contactId()); -} - -void BlackLister::addContact(const TQString &contactId) -{ - if( !isBlocked(contactId) ) - { - d->blacklist += contactId; - saveToDisk(); - emit contactAdded( contactId ); - } -} - -void BlackLister::addContact(Contact *contact) -{ - TQString temp = contact->contactId(); - - addContact( temp ); -} - -void BlackLister::removeContact(Contact *contact) -{ - TQString temp = contact->contactId(); - - removeContact( temp ); -} - -void BlackLister::saveToDisk() -{ - TDEConfig *config = TDEGlobal::config(); - - config->setGroup("BlackLister"); - config->writeEntry( d->protocol + TQString::fromLatin1("_") + d->owner, d->blacklist ); - config->sync(); -} - -void BlackLister::removeContact(const TQString &contactId) -{ - if( isBlocked(contactId) ) - { - d->blacklist.remove( contactId ); - saveToDisk(); - emit contactRemoved( contactId ); - } -} - -} - -#include "kopeteblacklister.moc" diff --git a/kopete/libkopete/kopeteblacklister.h b/kopete/libkopete/kopeteblacklister.h deleted file mode 100644 index 29bf9d79..00000000 --- a/kopete/libkopete/kopeteblacklister.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - kopeteblacklister.h - Kopete BlackLister - - Copyright (c) 2004 by Roie Kerstein - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef KOPETEBLACKLISTER_H -#define KOPETEBLACKLISTER_H - -#include - -namespace Kopete -{ - -class Contact; - -/** - * @brief Manages the list of blacklisted contacts for an account - * - * This class manages the list of contacts the user wishes - * to ignore permanently. In order to use the this class, there is no need to - * create an instance. Use the @ref Kopete::Account::blackLister() instead. - * - * Keep in mind that this class does not discard messages from blocked - * users - It only manages the list. It is the up to the protocol to - * check whether a user is blocked, and act accordingly. A protocol may - * re-implement @ref Kopete::Account::block() and @ref Kopete::Account::unblock() - * and use @ref Kopete::Account::blackLister() as a persistent list manager - * only, or connect the signals @ref contactAdded() and @ref contactRemoved() - * to its slots. - * - * @sa Kopete::Account::block() Kopete::Account::unblock() - * - * @author Roie Kerstein - */ -class BlackLister : public TQObject -{ - Q_OBJECT - - -public: - /** - * Create an instance, and read the blacklist from disk if it exists. - * @param protocolId is the ID of the protocol owning accountId - * @param accountId is the ID of the owning Account. - * @param parent The TQObject parent for this class. - * @param name The TQObject name for this class. - */ - BlackLister( const TQString &protocolId, const TQString &accountId, TQObject *parent = 0, const char *name = 0 ); - ~BlackLister(); - - /** - * \return @c true if @p contact is blocked, @c false otherwise. - */ - bool isBlocked( Contact *contact ); - - /** - * \return @c true if the contact with ID @p contactId is blocked, @c false otherwise. - */ - bool isBlocked( const TQString &contactId ); - -public slots: - /** - * Add a contact to the blacklist. - * - * This function emits the @ref contactAdded() signal. - * @param contactId is the ID of the contact to be added to the list. - */ - void addContact( const TQString &contactId ); - - /** - * @overload - */ - void addContact( Contact *contact ); - - /** - * \brief Remove a contact from the blacklist. - * - * Removes the contact from the blacklist. - * This function emits the @ref contactRemoved() signal. - * @param contact is the contact to be removed from the list. - */ - void removeContact( Contact *contact ); - - /** - * @overload - */ - void removeContact( const TQString &contactId ); - -signals: - /** - * \brief A new contact has been added to the list - * - * Connect to this signal if you want to perform additional actions, - * and you prefer not to derive from this class. - */ - void contactAdded( const TQString &contactId ); - - /** - * \brief A contact has been removed from the list - * - * Connect to this signal if you want to perform additional actions, - * and you prefer not to derive from this class. - */ - void contactRemoved( const TQString &contactId ); - -private: - void saveToDisk(); - - class Private; - Private *d; -}; - -} - -#endif diff --git a/kopete/libkopete/kopeteblactdelister.cpp b/kopete/libkopete/kopeteblactdelister.cpp new file mode 100644 index 00000000..e249d736 --- /dev/null +++ b/kopete/libkopete/kopeteblactdelister.cpp @@ -0,0 +1,109 @@ +/* + kopeteblacklister.cpp - Kopete BlackLister + + Copyright (c) 2004 by Roie Kerstein + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopeteblacklister.h" + +#include "kopetecontact.h" + +#include +#include + +#include + +namespace Kopete +{ + +class BlackLister::Private +{ +public: + TQStringList blacklist; + TQString owner; + TQString protocol; +}; + + +BlackLister::BlackLister(const TQString &protocolId, const TQString &accountId, TQObject *parent, const char *name) + : TQObject(parent, name), d( new Private ) +{ + TDEConfig *config = TDEGlobal::config(); + + d->owner = accountId; + d->protocol = protocolId; + config->setGroup("BlackLister"); + d->blacklist = config->readListEntry( d->protocol + TQString::fromLatin1("_") + d->owner ); +} + +BlackLister::~BlackLister() +{ + delete d; +} + + +bool BlackLister::isBlocked(const TQString &contactId) +{ + return (d->blacklist.find( contactId ) != d->blacklist.end() ); +} + +bool BlackLister::isBlocked(Contact *contact) +{ + return isBlocked(contact->contactId()); +} + +void BlackLister::addContact(const TQString &contactId) +{ + if( !isBlocked(contactId) ) + { + d->blacklist += contactId; + saveToDisk(); + emit contactAdded( contactId ); + } +} + +void BlackLister::addContact(Contact *contact) +{ + TQString temp = contact->contactId(); + + addContact( temp ); +} + +void BlackLister::removeContact(Contact *contact) +{ + TQString temp = contact->contactId(); + + removeContact( temp ); +} + +void BlackLister::saveToDisk() +{ + TDEConfig *config = TDEGlobal::config(); + + config->setGroup("BlackLister"); + config->writeEntry( d->protocol + TQString::fromLatin1("_") + d->owner, d->blacklist ); + config->sync(); +} + +void BlackLister::removeContact(const TQString &contactId) +{ + if( isBlocked(contactId) ) + { + d->blacklist.remove( contactId ); + saveToDisk(); + emit contactRemoved( contactId ); + } +} + +} + +#include "kopeteblacklister.moc" diff --git a/kopete/libkopete/kopeteblactdelister.h b/kopete/libkopete/kopeteblactdelister.h new file mode 100644 index 00000000..29bf9d79 --- /dev/null +++ b/kopete/libkopete/kopeteblactdelister.h @@ -0,0 +1,125 @@ +/* + kopeteblacklister.h - Kopete BlackLister + + Copyright (c) 2004 by Roie Kerstein + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KOPETEBLACKLISTER_H +#define KOPETEBLACKLISTER_H + +#include + +namespace Kopete +{ + +class Contact; + +/** + * @brief Manages the list of blacklisted contacts for an account + * + * This class manages the list of contacts the user wishes + * to ignore permanently. In order to use the this class, there is no need to + * create an instance. Use the @ref Kopete::Account::blackLister() instead. + * + * Keep in mind that this class does not discard messages from blocked + * users - It only manages the list. It is the up to the protocol to + * check whether a user is blocked, and act accordingly. A protocol may + * re-implement @ref Kopete::Account::block() and @ref Kopete::Account::unblock() + * and use @ref Kopete::Account::blackLister() as a persistent list manager + * only, or connect the signals @ref contactAdded() and @ref contactRemoved() + * to its slots. + * + * @sa Kopete::Account::block() Kopete::Account::unblock() + * + * @author Roie Kerstein + */ +class BlackLister : public TQObject +{ + Q_OBJECT + + +public: + /** + * Create an instance, and read the blacklist from disk if it exists. + * @param protocolId is the ID of the protocol owning accountId + * @param accountId is the ID of the owning Account. + * @param parent The TQObject parent for this class. + * @param name The TQObject name for this class. + */ + BlackLister( const TQString &protocolId, const TQString &accountId, TQObject *parent = 0, const char *name = 0 ); + ~BlackLister(); + + /** + * \return @c true if @p contact is blocked, @c false otherwise. + */ + bool isBlocked( Contact *contact ); + + /** + * \return @c true if the contact with ID @p contactId is blocked, @c false otherwise. + */ + bool isBlocked( const TQString &contactId ); + +public slots: + /** + * Add a contact to the blacklist. + * + * This function emits the @ref contactAdded() signal. + * @param contactId is the ID of the contact to be added to the list. + */ + void addContact( const TQString &contactId ); + + /** + * @overload + */ + void addContact( Contact *contact ); + + /** + * \brief Remove a contact from the blacklist. + * + * Removes the contact from the blacklist. + * This function emits the @ref contactRemoved() signal. + * @param contact is the contact to be removed from the list. + */ + void removeContact( Contact *contact ); + + /** + * @overload + */ + void removeContact( const TQString &contactId ); + +signals: + /** + * \brief A new contact has been added to the list + * + * Connect to this signal if you want to perform additional actions, + * and you prefer not to derive from this class. + */ + void contactAdded( const TQString &contactId ); + + /** + * \brief A contact has been removed from the list + * + * Connect to this signal if you want to perform additional actions, + * and you prefer not to derive from this class. + */ + void contactRemoved( const TQString &contactId ); + +private: + void saveToDisk(); + + class Private; + Private *d; +}; + +} + +#endif diff --git a/kopete/libkopete/ui/addressbookselectordialog.cpp b/kopete/libkopete/ui/addressbookselectordialog.cpp deleted file mode 100644 index 44f42e2a..00000000 --- a/kopete/libkopete/ui/addressbookselectordialog.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - AddressBookSelectorDialog - Nice Dialog to select a KDE AddressBook contact - - Copyright (c) 2005 by Duncan Mac-Vicar Prett - - Kopete (c) 2002-2005 by the Kopete developers - - ************************************************************************* - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ************************************************************************* -*/ - -#include "addressbookselectordialog.h" -#include "addressbookselectorwidget.h" -#include -#include -#include -#include -#include -#include - -namespace Kopete -{ -namespace UI -{ - -AddressBookSelectorDialog::AddressBookSelectorDialog(const TQString &title, const TQString &message, const TQString &preSelectUid, TQWidget *parent, const char *name, bool modal ) : KDialogBase(parent, name, modal, title, Help|Ok|Cancel, Ok, true ) -{ - TQVBox *vbox=new TQVBox(this); - m_addressBookSelectorWidget= new AddressBookSelectorWidget(vbox); - m_addressBookSelectorWidget->setLabelMessage(message); - - vbox->setSpacing( KDialog::spacingHint() ); - - setMainWidget(vbox); - enableButtonOK(false); - //setHelp("linkaddressbook"); - - connect(m_addressBookSelectorWidget, TQT_SIGNAL(addresseeListClicked( TQListViewItem * )), TQT_SLOT(slotWidgetAddresseeListClicked( TQListViewItem * ))); - - if ( !preSelectUid.isEmpty() ) - m_addressBookSelectorWidget->selectAddressee(preSelectUid); -} - -AddressBookSelectorDialog::~AddressBookSelectorDialog() -{ -} - -KABC::Addressee AddressBookSelectorDialog::getAddressee( const TQString &title, const TQString &message, const TQString &preSelectUid, TQWidget *parent) -{ - AddressBookSelectorDialog dialog(title, message, preSelectUid, parent); - int result = dialog.exec(); - - KABC::Addressee adr; - if ( result == TQDialog::Accepted ) - adr = dialog.addressBookSelectorWidget()->addressee(); - - return adr; -} - -void AddressBookSelectorDialog::slotWidgetAddresseeListClicked( TQListViewItem *addressee ) -{ - // enable ok if a valid addressee is selected - enableButtonOK( addressee ? addressee->isSelected() : false); -} - -void AddressBookSelectorDialog::accept() -{ - TQDialog::accept(); -} - -void AddressBookSelectorDialog::reject() -{ - TQDialog::reject(); -} - -} // namespace UI -} // namespace Kopete - -#include "addressbookselectordialog.moc" - -// vim: set noet ts=4 sts=4 sw=4: - diff --git a/kopete/libkopete/ui/addressbookselectordialog.h b/kopete/libkopete/ui/addressbookselectordialog.h deleted file mode 100644 index 5f5f6500..00000000 --- a/kopete/libkopete/ui/addressbookselectordialog.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - AddressBookSelectorDialog - Nice Dialog to select a KDE AddressBook contact - - Copyright (c) 2005 by Duncan Mac-Vicar Prett - - Kopete (c) 2002-2005 by the Kopete developers - - ************************************************************************* - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef ADDRESSBOOKSELECTORDIALOG_H -#define ADDRESSBOOKSELECTORDIALOG_H - -#include -#include "kopete_export.h" -#include - -namespace KABC -{ - class AddressBook; - class Addressee; -} - -namespace Kopete -{ -namespace UI -{ - -class AddressBookSelectorWidget; - -/** - * A dialog that uses AddressBookSelectorWidget to allow the user - * to select a KDE addressbook contact. If you want to use special features - * you can use @see addressBookSelectorWidget() to get the pointer to the - * AddressBookSelectorWidget object and set the desired options there. - * - * @author Duncan Mac-Vicar Prett - */ -class KOPETE_EXPORT AddressBookSelectorDialog : public KDialogBase -{ - Q_OBJECT - -public: - /** - * The constructor of an empty AddressBookSelectorWidget - */ - AddressBookSelectorDialog( const TQString &title, const TQString &message, const TQString &preSelectUid, TQWidget *parent=0L, const char *name=0L, bool modal = false ); - /** - * The destructor of the dialog - */ - ~AddressBookSelectorDialog(); - - /** - * @returns the AddressBookSelectorWidget widget so that additional - * parameters can be set by using it. - */ - AddressBookSelectorWidget *addressBookSelectorWidget() const - { return m_addressBookSelectorWidget; }; - - /** - * Creates a modal dialog, lets the user to select a addressbook contact - * and returns when the dialog is closed. - * - * @returns the selected contact, or a null addressee if the user - * pressed the Cancel button. Optionally - */ - static KABC::Addressee getAddressee( const TQString &title, const TQString &message, const TQString &preSelectUid, TQWidget *parent = 0L ); - -protected slots: - virtual void accept(); - virtual void reject(); - void slotWidgetAddresseeListClicked( TQListViewItem *addressee ); -protected: - AddressBookSelectorWidget *m_addressBookSelectorWidget; -}; - -} // namespace UI -} // namespace Kopete - -#endif - -// vim: set noet ts=4 sts=4 sw=4: - diff --git a/kopete/libkopete/ui/addressbookselectorwidget.cpp b/kopete/libkopete/ui/addressbookselectorwidget.cpp deleted file mode 100644 index 16009ee5..00000000 --- a/kopete/libkopete/ui/addressbookselectorwidget.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - AddressBookSelectorWidget - - Copyright (c) 2005 by Duncan Mac-Vicar Prett - - Based on LinkAddressBookUI whose code was shamelessly stolen from - kopete's add new contact wizard, used in Konversation, and then - reappropriated by Kopete. - - LinkAddressBookUI: - Copyright (c) 2004 by John Tapsell - Copyright (c) 2003-2005 by Will Stephenson - Copyright (c) 2002 by Nick Betcher - Copyright (c) 2002 by Duncan Mac-Vicar Prett - - Kopete (c) 2002-2004 by the Kopete developers - - ************************************************************************* - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ************************************************************************* -*/ - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "addressbookselectorwidget.h" -#include -#include "kabcpersistence.h" - -using namespace Kopete::UI; - -namespace Kopete -{ -namespace UI -{ - -AddressBookSelectorWidget::AddressBookSelectorWidget( TQWidget *parent, const char *name ) - : AddressBookSelectorWidget_Base( parent, name ) -{ - m_addressBook = Kopete::KABCPersistence::self()->addressBook(); - - // Addressee validation connections - connect( addAddresseeButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotAddAddresseeClicked() ) ); - connect( addAddresseeButton, TQT_SIGNAL( clicked() ), TQT_SIGNAL( addAddresseeClicked() ) ); - - connect( addresseeListView, TQT_SIGNAL( clicked(TQListViewItem * ) ), - TQT_SIGNAL( addresseeListClicked( TQListViewItem * ) ) ); - connect( addresseeListView, TQT_SIGNAL( selectionChanged( TQListViewItem * ) ), - TQT_SIGNAL( addresseeListClicked( TQListViewItem * ) ) ); - connect( addresseeListView, TQT_SIGNAL( spacePressed( TQListViewItem * ) ), - TQT_SIGNAL( addresseeListClicked( TQListViewItem * ) ) ); - - connect( m_addressBook, TQT_SIGNAL( addressBookChanged( AddressBook * ) ), this, TQT_SLOT( slotLoadAddressees() ) ); - - //We should add a clear TDEAction here. But we can't really do that with a designer file :\ this sucks - - addresseeListView->setColumnText(2, SmallIconSet(TQString::fromLatin1("email")), i18n("Email")); - - kListViewSearchLine->setListView(addresseeListView); - slotLoadAddressees(); - - addresseeListView->setColumnWidthMode(0, TQListView::Manual); - addresseeListView->setColumnWidth(0, 63); //Photo is 60, and it's nice to have a small gap, imho -} - - -AddressBookSelectorWidget::~AddressBookSelectorWidget() -{ - disconnect( m_addressBook, TQT_SIGNAL( addressBookChanged( AddressBook * ) ), this, TQT_SLOT( slotLoadAddressees() ) ); -} - - -KABC::Addressee AddressBookSelectorWidget::addressee() -{ - AddresseeItem *item = 0L; - item = static_cast( addresseeListView->selectedItem() ); - - if ( item ) - m_addressee = item->addressee(); - - return m_addressee; -} - -void AddressBookSelectorWidget::selectAddressee( const TQString &uid ) -{ - // iterate trough list view - TQListViewItemIterator it( addresseeListView ); - while( it.current() ) - { - AddresseeItem *addrItem = (AddresseeItem *) it.current(); - if ( addrItem->addressee().uid() == uid ) - { - // select the contact item - addresseeListView->setSelected( addrItem, true ); - addresseeListView->ensureItemVisible( addrItem ); - } - ++it; - } -} - -bool AddressBookSelectorWidget::addresseeSelected() -{ - return addresseeListView->selectedItem() ? true : false; -} - -/** Read in contacts from addressbook, and select the contact that is for our nick. */ -void AddressBookSelectorWidget::slotLoadAddressees() -{ - addresseeListView->clear(); - KABC::AddressBook::Iterator it; - AddresseeItem *addr; - for( it = m_addressBook->begin(); it != m_addressBook->end(); ++it ) - { - addr = new AddresseeItem( addresseeListView, (*it)); - } - -} - -void AddressBookSelectorWidget::setLabelMessage( const TQString &msg ) -{ - lblHeader->setText(msg); -} - -void AddressBookSelectorWidget::slotAddAddresseeClicked() -{ - // Pop up add addressee dialog - TQString addresseeName = KInputDialog::getText( i18n( "New Address Book Entry" ), i18n( "Name the new entry:" ), TQString(), 0, this ); - - if ( !addresseeName.isEmpty() ) - { - KABC::Addressee addr; - addr.setNameFromString( addresseeName ); - m_addressBook->insertAddressee(addr); - Kopete::KABCPersistence::self()->writeAddressBook( 0 ); - slotLoadAddressees(); - // select the addressee we just added - TQListViewItem * added = addresseeListView->findItem( addresseeName, 1 ); - kListViewSearchLine->clear(); - kListViewSearchLine->updateSearch(); - addresseeListView->setSelected( added, true ); - addresseeListView->ensureItemVisible( added ); - } -} - -} // namespace UI -} // namespace Kopete - -#include "addressbookselectorwidget.moc" - -// vim: set noet ts=4 sts=4 sw=4: - diff --git a/kopete/libkopete/ui/addressbookselectorwidget.h b/kopete/libkopete/ui/addressbookselectorwidget.h deleted file mode 100644 index af4b1834..00000000 --- a/kopete/libkopete/ui/addressbookselectorwidget.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - AddressBookSelectorWidget - Copyright (c) 2005 by Duncan Mac-Vicar Prett - - Based on LinkAddressBookUI whose code was shamelessly stolen from - kopete's add new contact wizard, used in Konversation, and then - reappropriated by Kopete. - - LinkAddressBookUI: - Copyright (c) 2004 by John Tapsell - Copyright (c) 2003-2005 by Will Stephenson - Copyright (c) 2002 by Nick Betcher - Copyright (c) 2002 by Duncan Mac-Vicar Prett - - Kopete (c) 2002-2004 by the Kopete developers - - ************************************************************************* - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef AddressBookSelectorWidget_H -#define AddressBookSelectorWidget_H - -#include -#include - -#include -#include "kopete_export.h" - -#include "addressbookselectorwidget_base.h" - -namespace KABC { - class AddressBook; - class Addressee; -} - -namespace Kopete -{ -namespace UI -{ - -class KOPETE_EXPORT AddressBookSelectorWidget : public AddressBookSelectorWidget_Base -{ - Q_OBJECT - -public: - AddressBookSelectorWidget( TQWidget *parent = 0, const char *name = 0 ); - ~AddressBookSelectorWidget(); - KABC::Addressee addressee(); - /** - * sets the widget label message - * example: Please select a contact - * or, Choose a contact to delete - */ - void setLabelMessage( const TQString &msg ); - /** - * pre-selects a contact - */ - void selectAddressee( const TQString &uid ); - /** - * @return true if there is a contact selected - */ - bool addresseeSelected(); - -private: - KABC::AddressBook * m_addressBook; - KABC::Addressee m_addressee; - -protected slots: - void slotAddAddresseeClicked(); - /** - * Utility function, populates the addressee list - */ - void slotLoadAddressees(); -signals: - void addresseeListClicked( TQListViewItem *addressee ); - void addAddresseeClicked(); -}; - -} // namespace UI -} // namespace Kopete - -#endif - -// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/addressbookselectorwidget_base.ui b/kopete/libkopete/ui/addressbookselectorwidget_base.ui deleted file mode 100644 index ee4c2016..00000000 --- a/kopete/libkopete/ui/addressbookselectorwidget_base.ui +++ /dev/null @@ -1,175 +0,0 @@ - -AddressBookSelectorWidget_Base - - - AddressBookSelectorWidget_Base - - - - 0 - 0 - 596 - 572 - - - - - 5 - 1 - 0 - 0 - - - - Select Contact - - - - unnamed - - - 0 - - - - spacer11 - - - Horizontal - - - Expanding - - - - 405 - 20 - - - - - - addAddresseeButton - - - Create New Entr&y... - - - Create a new entry in your address book - - - - - lblHeader - - - - 7 - 4 - 0 - 0 - - - - - - - Photo - - - false - - - true - - - - - Name - - - true - - - true - - - - - Email - - - true - - - true - - - - addresseeListView - - - - 7 - 7 - 0 - 10 - - - - true - - - LastColumn - - - Select the contact you want to communicate with via Instant Messaging - - - - - layout1 - - - - unnamed - - - - lblSearch - - - - 1 - 5 - 0 - 0 - - - - S&earch: - - - kListViewSearchLine - - - - - kListViewSearchLine - - - - - - - - klistviewsearchline.h - - - - - kactivelabel.h - klistview.h - klistviewsearchline.h - - diff --git a/kopete/libkopete/ui/addressbootdeselectordialog.cpp b/kopete/libkopete/ui/addressbootdeselectordialog.cpp new file mode 100644 index 00000000..44f42e2a --- /dev/null +++ b/kopete/libkopete/ui/addressbootdeselectordialog.cpp @@ -0,0 +1,89 @@ +/* + AddressBookSelectorDialog + Nice Dialog to select a KDE AddressBook contact + + Copyright (c) 2005 by Duncan Mac-Vicar Prett + + Kopete (c) 2002-2005 by the Kopete developers + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "addressbookselectordialog.h" +#include "addressbookselectorwidget.h" +#include +#include +#include +#include +#include +#include + +namespace Kopete +{ +namespace UI +{ + +AddressBookSelectorDialog::AddressBookSelectorDialog(const TQString &title, const TQString &message, const TQString &preSelectUid, TQWidget *parent, const char *name, bool modal ) : KDialogBase(parent, name, modal, title, Help|Ok|Cancel, Ok, true ) +{ + TQVBox *vbox=new TQVBox(this); + m_addressBookSelectorWidget= new AddressBookSelectorWidget(vbox); + m_addressBookSelectorWidget->setLabelMessage(message); + + vbox->setSpacing( KDialog::spacingHint() ); + + setMainWidget(vbox); + enableButtonOK(false); + //setHelp("linkaddressbook"); + + connect(m_addressBookSelectorWidget, TQT_SIGNAL(addresseeListClicked( TQListViewItem * )), TQT_SLOT(slotWidgetAddresseeListClicked( TQListViewItem * ))); + + if ( !preSelectUid.isEmpty() ) + m_addressBookSelectorWidget->selectAddressee(preSelectUid); +} + +AddressBookSelectorDialog::~AddressBookSelectorDialog() +{ +} + +KABC::Addressee AddressBookSelectorDialog::getAddressee( const TQString &title, const TQString &message, const TQString &preSelectUid, TQWidget *parent) +{ + AddressBookSelectorDialog dialog(title, message, preSelectUid, parent); + int result = dialog.exec(); + + KABC::Addressee adr; + if ( result == TQDialog::Accepted ) + adr = dialog.addressBookSelectorWidget()->addressee(); + + return adr; +} + +void AddressBookSelectorDialog::slotWidgetAddresseeListClicked( TQListViewItem *addressee ) +{ + // enable ok if a valid addressee is selected + enableButtonOK( addressee ? addressee->isSelected() : false); +} + +void AddressBookSelectorDialog::accept() +{ + TQDialog::accept(); +} + +void AddressBookSelectorDialog::reject() +{ + TQDialog::reject(); +} + +} // namespace UI +} // namespace Kopete + +#include "addressbookselectordialog.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/addressbootdeselectordialog.h b/kopete/libkopete/ui/addressbootdeselectordialog.h new file mode 100644 index 00000000..5f5f6500 --- /dev/null +++ b/kopete/libkopete/ui/addressbootdeselectordialog.h @@ -0,0 +1,91 @@ +/* + AddressBookSelectorDialog + Nice Dialog to select a KDE AddressBook contact + + Copyright (c) 2005 by Duncan Mac-Vicar Prett + + Kopete (c) 2002-2005 by the Kopete developers + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef ADDRESSBOOKSELECTORDIALOG_H +#define ADDRESSBOOKSELECTORDIALOG_H + +#include +#include "kopete_export.h" +#include + +namespace KABC +{ + class AddressBook; + class Addressee; +} + +namespace Kopete +{ +namespace UI +{ + +class AddressBookSelectorWidget; + +/** + * A dialog that uses AddressBookSelectorWidget to allow the user + * to select a KDE addressbook contact. If you want to use special features + * you can use @see addressBookSelectorWidget() to get the pointer to the + * AddressBookSelectorWidget object and set the desired options there. + * + * @author Duncan Mac-Vicar Prett + */ +class KOPETE_EXPORT AddressBookSelectorDialog : public KDialogBase +{ + Q_OBJECT + +public: + /** + * The constructor of an empty AddressBookSelectorWidget + */ + AddressBookSelectorDialog( const TQString &title, const TQString &message, const TQString &preSelectUid, TQWidget *parent=0L, const char *name=0L, bool modal = false ); + /** + * The destructor of the dialog + */ + ~AddressBookSelectorDialog(); + + /** + * @returns the AddressBookSelectorWidget widget so that additional + * parameters can be set by using it. + */ + AddressBookSelectorWidget *addressBookSelectorWidget() const + { return m_addressBookSelectorWidget; }; + + /** + * Creates a modal dialog, lets the user to select a addressbook contact + * and returns when the dialog is closed. + * + * @returns the selected contact, or a null addressee if the user + * pressed the Cancel button. Optionally + */ + static KABC::Addressee getAddressee( const TQString &title, const TQString &message, const TQString &preSelectUid, TQWidget *parent = 0L ); + +protected slots: + virtual void accept(); + virtual void reject(); + void slotWidgetAddresseeListClicked( TQListViewItem *addressee ); +protected: + AddressBookSelectorWidget *m_addressBookSelectorWidget; +}; + +} // namespace UI +} // namespace Kopete + +#endif + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/addressbootdeselectorwidget.cpp b/kopete/libkopete/ui/addressbootdeselectorwidget.cpp new file mode 100644 index 00000000..16009ee5 --- /dev/null +++ b/kopete/libkopete/ui/addressbootdeselectorwidget.cpp @@ -0,0 +1,171 @@ +/* + AddressBookSelectorWidget + + Copyright (c) 2005 by Duncan Mac-Vicar Prett + + Based on LinkAddressBookUI whose code was shamelessly stolen from + kopete's add new contact wizard, used in Konversation, and then + reappropriated by Kopete. + + LinkAddressBookUI: + Copyright (c) 2004 by John Tapsell + Copyright (c) 2003-2005 by Will Stephenson + Copyright (c) 2002 by Nick Betcher + Copyright (c) 2002 by Duncan Mac-Vicar Prett + + Kopete (c) 2002-2004 by the Kopete developers + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "addressbookselectorwidget.h" +#include +#include "kabcpersistence.h" + +using namespace Kopete::UI; + +namespace Kopete +{ +namespace UI +{ + +AddressBookSelectorWidget::AddressBookSelectorWidget( TQWidget *parent, const char *name ) + : AddressBookSelectorWidget_Base( parent, name ) +{ + m_addressBook = Kopete::KABCPersistence::self()->addressBook(); + + // Addressee validation connections + connect( addAddresseeButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotAddAddresseeClicked() ) ); + connect( addAddresseeButton, TQT_SIGNAL( clicked() ), TQT_SIGNAL( addAddresseeClicked() ) ); + + connect( addresseeListView, TQT_SIGNAL( clicked(TQListViewItem * ) ), + TQT_SIGNAL( addresseeListClicked( TQListViewItem * ) ) ); + connect( addresseeListView, TQT_SIGNAL( selectionChanged( TQListViewItem * ) ), + TQT_SIGNAL( addresseeListClicked( TQListViewItem * ) ) ); + connect( addresseeListView, TQT_SIGNAL( spacePressed( TQListViewItem * ) ), + TQT_SIGNAL( addresseeListClicked( TQListViewItem * ) ) ); + + connect( m_addressBook, TQT_SIGNAL( addressBookChanged( AddressBook * ) ), this, TQT_SLOT( slotLoadAddressees() ) ); + + //We should add a clear TDEAction here. But we can't really do that with a designer file :\ this sucks + + addresseeListView->setColumnText(2, SmallIconSet(TQString::fromLatin1("email")), i18n("Email")); + + kListViewSearchLine->setListView(addresseeListView); + slotLoadAddressees(); + + addresseeListView->setColumnWidthMode(0, TQListView::Manual); + addresseeListView->setColumnWidth(0, 63); //Photo is 60, and it's nice to have a small gap, imho +} + + +AddressBookSelectorWidget::~AddressBookSelectorWidget() +{ + disconnect( m_addressBook, TQT_SIGNAL( addressBookChanged( AddressBook * ) ), this, TQT_SLOT( slotLoadAddressees() ) ); +} + + +KABC::Addressee AddressBookSelectorWidget::addressee() +{ + AddresseeItem *item = 0L; + item = static_cast( addresseeListView->selectedItem() ); + + if ( item ) + m_addressee = item->addressee(); + + return m_addressee; +} + +void AddressBookSelectorWidget::selectAddressee( const TQString &uid ) +{ + // iterate trough list view + TQListViewItemIterator it( addresseeListView ); + while( it.current() ) + { + AddresseeItem *addrItem = (AddresseeItem *) it.current(); + if ( addrItem->addressee().uid() == uid ) + { + // select the contact item + addresseeListView->setSelected( addrItem, true ); + addresseeListView->ensureItemVisible( addrItem ); + } + ++it; + } +} + +bool AddressBookSelectorWidget::addresseeSelected() +{ + return addresseeListView->selectedItem() ? true : false; +} + +/** Read in contacts from addressbook, and select the contact that is for our nick. */ +void AddressBookSelectorWidget::slotLoadAddressees() +{ + addresseeListView->clear(); + KABC::AddressBook::Iterator it; + AddresseeItem *addr; + for( it = m_addressBook->begin(); it != m_addressBook->end(); ++it ) + { + addr = new AddresseeItem( addresseeListView, (*it)); + } + +} + +void AddressBookSelectorWidget::setLabelMessage( const TQString &msg ) +{ + lblHeader->setText(msg); +} + +void AddressBookSelectorWidget::slotAddAddresseeClicked() +{ + // Pop up add addressee dialog + TQString addresseeName = KInputDialog::getText( i18n( "New Address Book Entry" ), i18n( "Name the new entry:" ), TQString(), 0, this ); + + if ( !addresseeName.isEmpty() ) + { + KABC::Addressee addr; + addr.setNameFromString( addresseeName ); + m_addressBook->insertAddressee(addr); + Kopete::KABCPersistence::self()->writeAddressBook( 0 ); + slotLoadAddressees(); + // select the addressee we just added + TQListViewItem * added = addresseeListView->findItem( addresseeName, 1 ); + kListViewSearchLine->clear(); + kListViewSearchLine->updateSearch(); + addresseeListView->setSelected( added, true ); + addresseeListView->ensureItemVisible( added ); + } +} + +} // namespace UI +} // namespace Kopete + +#include "addressbookselectorwidget.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/libkopete/ui/addressbootdeselectorwidget.h b/kopete/libkopete/ui/addressbootdeselectorwidget.h new file mode 100644 index 00000000..af4b1834 --- /dev/null +++ b/kopete/libkopete/ui/addressbootdeselectorwidget.h @@ -0,0 +1,91 @@ +/* + AddressBookSelectorWidget + Copyright (c) 2005 by Duncan Mac-Vicar Prett + + Based on LinkAddressBookUI whose code was shamelessly stolen from + kopete's add new contact wizard, used in Konversation, and then + reappropriated by Kopete. + + LinkAddressBookUI: + Copyright (c) 2004 by John Tapsell + Copyright (c) 2003-2005 by Will Stephenson + Copyright (c) 2002 by Nick Betcher + Copyright (c) 2002 by Duncan Mac-Vicar Prett + + Kopete (c) 2002-2004 by the Kopete developers + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef AddressBookSelectorWidget_H +#define AddressBookSelectorWidget_H + +#include +#include + +#include +#include "kopete_export.h" + +#include "addressbookselectorwidget_base.h" + +namespace KABC { + class AddressBook; + class Addressee; +} + +namespace Kopete +{ +namespace UI +{ + +class KOPETE_EXPORT AddressBookSelectorWidget : public AddressBookSelectorWidget_Base +{ + Q_OBJECT + +public: + AddressBookSelectorWidget( TQWidget *parent = 0, const char *name = 0 ); + ~AddressBookSelectorWidget(); + KABC::Addressee addressee(); + /** + * sets the widget label message + * example: Please select a contact + * or, Choose a contact to delete + */ + void setLabelMessage( const TQString &msg ); + /** + * pre-selects a contact + */ + void selectAddressee( const TQString &uid ); + /** + * @return true if there is a contact selected + */ + bool addresseeSelected(); + +private: + KABC::AddressBook * m_addressBook; + KABC::Addressee m_addressee; + +protected slots: + void slotAddAddresseeClicked(); + /** + * Utility function, populates the addressee list + */ + void slotLoadAddressees(); +signals: + void addresseeListClicked( TQListViewItem *addressee ); + void addAddresseeClicked(); +}; + +} // namespace UI +} // namespace Kopete + +#endif + +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/libkopete/ui/addressbootdeselectorwidget_base.ui b/kopete/libkopete/ui/addressbootdeselectorwidget_base.ui new file mode 100644 index 00000000..ee4c2016 --- /dev/null +++ b/kopete/libkopete/ui/addressbootdeselectorwidget_base.ui @@ -0,0 +1,175 @@ + +AddressBookSelectorWidget_Base + + + AddressBookSelectorWidget_Base + + + + 0 + 0 + 596 + 572 + + + + + 5 + 1 + 0 + 0 + + + + Select Contact + + + + unnamed + + + 0 + + + + spacer11 + + + Horizontal + + + Expanding + + + + 405 + 20 + + + + + + addAddresseeButton + + + Create New Entr&y... + + + Create a new entry in your address book + + + + + lblHeader + + + + 7 + 4 + 0 + 0 + + + + + + + Photo + + + false + + + true + + + + + Name + + + true + + + true + + + + + Email + + + true + + + true + + + + addresseeListView + + + + 7 + 7 + 0 + 10 + + + + true + + + LastColumn + + + Select the contact you want to communicate with via Instant Messaging + + + + + layout1 + + + + unnamed + + + + lblSearch + + + + 1 + 5 + 0 + 0 + + + + S&earch: + + + kListViewSearchLine + + + + + kListViewSearchLine + + + + + + + + klistviewsearchline.h + + + + + kactivelabel.h + klistview.h + klistviewsearchline.h + + diff --git a/ksirc/test/nicklist.pl b/ksirc/test/nicklist.pl deleted file mode 100644 index 948429eb..00000000 --- a/ksirc/test/nicklist.pl +++ /dev/null @@ -1,77 +0,0 @@ -sub rndchr { - my $string = ""; - for(my $i = 0; $i < 8; $i++){ - $string .= chr(int(rand(26)) + 97); # More or less the alpahbet - } - return $string; -} - -srand(time()); - -&timer(1, "&next_one", 1); - -$state = 0; -$max_nicks = 100; -$min_nicks = 5; -$num_nicks = 0; -%list_nicks = (); -$repeat = 100000; -$count = 0; - -@state = (\&join, \&part); - -$line = "~#test~*#* Users on #test:"; -for($i = 0; $i < $max_nicks; $i++){ - my($mynick) = rndchr(); - $list_nicks{$mynick} = 1; - $is_op = rand(100); - if($is_op > 50){ - $mynick = "@" . $mynick; - } - $line .= " " . $mynick; - $num_nicks ++; -} -print "$line\n"; - -sub next_one { - for(my($i) = 0; $i < 200; $i++){ - $goto_state = int(rand($#state+1)); - &{$state[$goto_state]}; - } - if($count++ < $repeat){ - &timer(1, "&next_one", 1); - } -} - -sub join{ - return if $num_nicks > $max_nicks; - my($mynick) = rndchr(); - $list_nicks{$mynick} = 1; - print("~#test~*>* $mynick (blah\@blah) has joined channel #test\n"); - $is_op = rand(100); - if($is_op > 75){ - print "~#test~*+* Mode change \"+o $mynick\" on channel #test by ChanServ\n"; - } - $is_voice = rand(100); - if($is_voice > 40){ - print "~#test~*+* Mode change \"+v $mynick\" on channel #test by ChanServ\n"; - } - $num_nicks ++; -} - -sub part{ - return if $num_nicks < $min_nicks; - AGAIN: { - my($times) = int(rand($num_nicks)); - for($i = 0; $i<= $times; $i++){ - ($mynick, $value) = each(%list_nicks); - } - return if $mynick eq ''; - } - next AGAIN if $value != 1; - $list_nicks{$mynick} = 0; - print("~#test~*<* $mynick has left channel #test\n"); - - delete $list_nicks{$mynick}; - $num_nicks --; -} diff --git a/ksirc/test/nictdelist.pl b/ksirc/test/nictdelist.pl new file mode 100644 index 00000000..948429eb --- /dev/null +++ b/ksirc/test/nictdelist.pl @@ -0,0 +1,77 @@ +sub rndchr { + my $string = ""; + for(my $i = 0; $i < 8; $i++){ + $string .= chr(int(rand(26)) + 97); # More or less the alpahbet + } + return $string; +} + +srand(time()); + +&timer(1, "&next_one", 1); + +$state = 0; +$max_nicks = 100; +$min_nicks = 5; +$num_nicks = 0; +%list_nicks = (); +$repeat = 100000; +$count = 0; + +@state = (\&join, \&part); + +$line = "~#test~*#* Users on #test:"; +for($i = 0; $i < $max_nicks; $i++){ + my($mynick) = rndchr(); + $list_nicks{$mynick} = 1; + $is_op = rand(100); + if($is_op > 50){ + $mynick = "@" . $mynick; + } + $line .= " " . $mynick; + $num_nicks ++; +} +print "$line\n"; + +sub next_one { + for(my($i) = 0; $i < 200; $i++){ + $goto_state = int(rand($#state+1)); + &{$state[$goto_state]}; + } + if($count++ < $repeat){ + &timer(1, "&next_one", 1); + } +} + +sub join{ + return if $num_nicks > $max_nicks; + my($mynick) = rndchr(); + $list_nicks{$mynick} = 1; + print("~#test~*>* $mynick (blah\@blah) has joined channel #test\n"); + $is_op = rand(100); + if($is_op > 75){ + print "~#test~*+* Mode change \"+o $mynick\" on channel #test by ChanServ\n"; + } + $is_voice = rand(100); + if($is_voice > 40){ + print "~#test~*+* Mode change \"+v $mynick\" on channel #test by ChanServ\n"; + } + $num_nicks ++; +} + +sub part{ + return if $num_nicks < $min_nicks; + AGAIN: { + my($times) = int(rand($num_nicks)); + for($i = 0; $i<= $times; $i++){ + ($mynick, $value) = each(%list_nicks); + } + return if $mynick eq ''; + } + next AGAIN if $value != 1; + $list_nicks{$mynick} = 0; + print("~#test~*<* $mynick has left channel #test\n"); + + delete $list_nicks{$mynick}; + $num_nicks --; +} -- cgit v1.2.1