You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2549 lines
67 KiB
2549 lines
67 KiB
15 years ago
|
/***************************************************************************
|
||
|
* 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 <pfeiffer@kde.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.
|
||
|
*
|
||
|
***************************************************************************/
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/ioctl.h>
|
||
|
#include <sys/socket.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
#ifdef __svr4__
|
||
|
#define map BULLSHIT // on Solaris it conflicts with STL ?
|
||
|
#include <net/if.h>
|
||
|
#undef map
|
||
|
#include <sys/sockio.h> // needed for SIOCGIFFLAGS
|
||
|
#else
|
||
|
#include <net/if.h>
|
||
|
#endif
|
||
|
|
||
13 years ago
|
#include <tqclipboard.h>
|
||
14 years ago
|
#include <tqregexp.h>
|
||
|
#include <tqdragobject.h>
|
||
|
#include <tqwhatsthis.h>
|
||
|
#include <tqtooltip.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqdropsite.h>
|
||
|
#include <tqpopupmenu.h>
|
||
|
#include <tqfileinfo.h>
|
||
15 years ago
|
#include <kinputdialog.h>
|
||
|
|
||
|
#include <kprotocolinfo.h>
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
15 years ago
|
#include <kapplication.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kurl.h>
|
||
|
#include <kurldrag.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kglobal.h>
|
||
13 years ago
|
#include <twin.h>
|
||
15 years ago
|
#include <kmessagebox.h>
|
||
|
#include <kstdaction.h>
|
||
|
#include <khelpmenu.h>
|
||
|
#include <kedittoolbar.h>
|
||
|
#include <kstatusbar.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
|
#include <tdeio/netaccess.h>
|
||
15 years ago
|
#include <knotifyclient.h>
|
||
|
#include <knotifydialog.h>
|
||
|
#include <kmenubar.h>
|
||
12 years ago
|
#include <tdeio/renamedlg.h>
|
||
15 years ago
|
|
||
|
#include "safedelete.h"
|
||
|
#include "settings.h"
|
||
|
#include "transfer.h"
|
||
|
#include "transferlist.h"
|
||
|
#include "kmainwidget.h"
|
||
12 years ago
|
#include "tdefileio.h"
|
||
15 years ago
|
#include "dlgPreferences.h"
|
||
|
#include "logwindow.h"
|
||
|
#include "docking.h"
|
||
|
#include "droptarget.h"
|
||
|
#include <assert.h>
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
#include <tdeio/authinfo.h>
|
||
|
#include <tdeio/global.h>
|
||
14 years ago
|
#include <tqiconset.h>
|
||
15 years ago
|
|
||
|
#include "version.h"
|
||
|
#include "slave.h"
|
||
|
#include "slaveevent.h"
|
||
|
|
||
|
struct KURLPair
|
||
|
{
|
||
|
KURL dest;
|
||
|
KURL src;
|
||
|
};
|
||
|
|
||
12 years ago
|
TDEMainWidget *kmain = 0L;
|
||
15 years ago
|
|
||
12 years ago
|
#define LOAD_ICON(X) TDEGlobal::iconLoader()->loadIcon(X, KIcon::MainToolbar)
|
||
15 years ago
|
|
||
|
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 */
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
TDEMainWidget::TDEMainWidget(bool bStartDocked)
|
||
15 years ago
|
: KGetIface( "KGet-Interface" ),
|
||
12 years ago
|
TDEMainWindow(0, "kget mainwindow",0),
|
||
15 years ago
|
prefDlg( 0 ), kdock( 0 )
|
||
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
{
|
||
12 years ago
|
TDEConfig cfg( "tdeioslaverc", false, false);
|
||
13 years ago
|
cfg.setGroup(TQString());
|
||
15 years ago
|
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
|
||
13 years ago
|
TQDate date = TQDateTime::currentDateTime().date();
|
||
|
TQTime time = TQDateTime::currentDateTime().time();
|
||
14 years ago
|
TQString tmp;
|
||
15 years ago
|
|
||
|
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;
|
||
|
|
||
13 years ago
|
lastClipboard = TQApplication::clipboard()->text( TQClipboard::Clipboard ).stripWhiteSpace();
|
||
12 years ago
|
// Load all settings from TDEConfig
|
||
15 years ago
|
ksettings.load();
|
||
|
|
||
|
// Setup log window
|
||
|
logWindow = new LogWindow();
|
||
|
|
||
|
m_showDropTarget = false;
|
||
|
|
||
|
setCaption(KGETVERSION);
|
||
|
|
||
|
setupGUI();
|
||
|
setupWhatsThis();
|
||
|
|
||
|
log(i18n("Welcome to KGet"));
|
||
|
|
||
|
setCentralWidget(myTransferList);
|
||
|
|
||
14 years ago
|
connect(kapp, TQT_SIGNAL(saveYourself()), TQT_SLOT(slotSaveYourself()));
|
||
15 years ago
|
|
||
|
// Enable dropping
|
||
|
setAcceptDrops(true);
|
||
|
|
||
|
// Setup connection timer
|
||
14 years ago
|
connectionTimer = new TQTimer(this);
|
||
|
connect(connectionTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotCheckConnection()));
|
||
15 years ago
|
|
||
|
// 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
|
||
14 years ago
|
animTimer = new TQTimer(this);
|
||
15 years ago
|
animCounter = 0;
|
||
14 years ago
|
connect(animTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotAnimTimeout()));
|
||
15 years ago
|
|
||
|
if (ksettings.b_useAnimation) {
|
||
|
animTimer->start(400);
|
||
|
} else {
|
||
|
animTimer->start(1000);
|
||
|
}
|
||
|
|
||
|
// Setup transfer timer for scheduled downloads and checkQueue()
|
||
14 years ago
|
transferTimer = new TQTimer(this);
|
||
|
connect(transferTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotTransferTimeout()));
|
||
15 years ago
|
transferTimer->start(10000); // 10 secs time interval
|
||
|
|
||
|
// Setup autosave timer
|
||
14 years ago
|
autosaveTimer = new TQTimer(this);
|
||
|
connect(autosaveTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotAutosaveTimeout()));
|
||
15 years ago
|
setAutoSave();
|
||
|
|
||
|
// Setup clipboard timer
|
||
14 years ago
|
clipboardTimer = new TQTimer(this);
|
||
|
connect(clipboardTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotCheckClipboard()));
|
||
15 years ago
|
if (ksettings.b_autoPaste) {
|
||
|
clipboardTimer->start(1000);
|
||
|
}
|
||
|
|
||
|
readTransfers();
|
||
|
|
||
|
// Setup special windows
|
||
|
kdrop = new DropTarget(this);
|
||
|
kdock = new DockWidget(this);
|
||
14 years ago
|
connect(kdock, TQT_SIGNAL(quitSelected()), TQT_SLOT(slotQuit()));
|
||
15 years ago
|
|
||
13 years ago
|
// Set geometry
|
||
15 years ago
|
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
|
||
13 years ago
|
setCaption(TQString(), false);
|
||
15 years ago
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
TDEMainWidget::~TDEMainWidget()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
delete prefDlg;
|
||
|
delete kdrop;
|
||
|
writeTransfers();
|
||
|
writeLog();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
delete logWindow;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::log(const TQString & message, bool statusbar)
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn <<" message= "<< message << endl;
|
||
|
#endif
|
||
|
|
||
|
logWindow->logGeneral(message);
|
||
|
|
||
|
if (statusbar) {
|
||
|
statusBar()->message(message, 1000);
|
||
|
}
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotSaveYourself()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
writeTransfers();
|
||
|
ksettings.save();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::setupGUI()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
// setup transfer list
|
||
|
myTransferList = new TransferList(this, "transferList");
|
||
|
myTransferList->setSorting(-1);
|
||
|
setListFont();
|
||
|
|
||
12 years ago
|
TDEActionCollection *coll = actionCollection();
|
||
15 years ago
|
|
||
14 years ago
|
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 *)));
|
||
15 years ago
|
|
||
|
// file actions
|
||
13 years ago
|
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");
|
||
15 years ago
|
|
||
12 years ago
|
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");
|
||
15 years ago
|
|
||
12 years ago
|
m_paImportText = new TDEAction(i18n("Import Text &File..."), 0, TQT_TQOBJECT(this), TQT_SLOT(slotImportTextFile()), coll, "import_text");
|
||
15 years ago
|
|
||
13 years ago
|
m_paQuit = KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(slotQuit()), coll, "quit");
|
||
15 years ago
|
|
||
|
|
||
|
// transfer actions
|
||
12 years ago
|
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");
|
||
15 years ago
|
|
||
12 years ago
|
m_paMoveToBegin = new TDEAction(i18n("Move to &Beginning"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotMoveToBegin()), coll, "move_begin");
|
||
15 years ago
|
|
||
12 years ago
|
m_paMoveToEnd = new TDEAction(i18n("Move to &End"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotMoveToEnd()), coll, "move_end");
|
||
15 years ago
|
#ifdef _DEBUG
|
||
|
sDebug << "Loading pics" << endl;
|
||
|
#endif
|
||
12 years ago
|
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");
|
||
15 years ago
|
|
||
12 years ago
|
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");
|
||
15 years ago
|
|
||
|
m_paQueue->setExclusiveGroup("TransferMode");
|
||
|
m_paTimer->setExclusiveGroup("TransferMode");
|
||
|
m_paDelay->setExclusiveGroup("TransferMode");
|
||
|
|
||
|
// options actions
|
||
12 years ago
|
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");
|
||
15 years ago
|
|
||
13 years ago
|
m_paPreferences = KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotPreferences()), coll);
|
||
15 years ago
|
|
||
14 years ago
|
KStdAction::keyBindings(guiFactory(), TQT_SLOT(configureShortcuts()), coll);
|
||
13 years ago
|
KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(slotConfigureToolbars()), coll);
|
||
|
KStdAction::configureNotifications(TQT_TQOBJECT(this), TQT_SLOT(slotConfigureNotifications()), coll);
|
||
15 years ago
|
|
||
13 years ago
|
m_menubarAction = KStdAction::showMenubar(TQT_TQOBJECT(this), TQT_SLOT(slotShowMenubar()), coll, "settings_showmenubar" );
|
||
15 years ago
|
m_menubarAction->setChecked( !menuBar()->isHidden() );
|
||
|
|
||
|
// view actions
|
||
|
createStandardStatusBarAction();
|
||
|
|
||
12 years ago
|
m_paShowLog = new TDEToggleAction(i18n("Show &Log Window"),"tool_logwindow", 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleLogWindow()), coll, "toggle_log");
|
||
15 years ago
|
m_paShowLog->setCheckedState(i18n("Hide &Log Window"));
|
||
12 years ago
|
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");
|
||
15 years ago
|
if (ksettings.b_KonquerorIntegration) {
|
||
|
m_paKonquerorIntegration->setText(i18n("Disable &KGet as Konqueror Download Manager"));
|
||
|
}
|
||
|
|
||
12 years ago
|
menuHelp = new KHelpMenu(this, TDEGlobal::instance()->aboutData());
|
||
14 years ago
|
KStdAction::whatsThis(menuHelp, TQT_SLOT(contextHelpActivated()), coll, "whats_this");
|
||
15 years ago
|
|
||
|
createGUI("kgetui.rc");
|
||
|
|
||
|
// setup statusbar
|
||
13 years ago
|
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);
|
||
12 years ago
|
statusBar()->insertFixedItem(i18n(" Time: %1 ").arg(TDEIO::convertSeconds(0)), ID_TOTAL_TIME);
|
||
13 years ago
|
statusBar()->insertFixedItem(i18n(" %1 KB/s ").arg("123.34"), ID_TOTAL_SPEED);
|
||
15 years ago
|
|
||
|
setAutoSaveSettings( "MainWindow", false /*Settings takes care of size & pos & state */ );
|
||
|
|
||
|
slotUpdateActions();
|
||
|
|
||
|
updateStatusBar();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::setupWhatsThis()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
14 years ago
|
TQString tmp;
|
||
15 years ago
|
|
||
|
tmp = i18n("<b>Resume</b> button starts selected transfers\n" "and sets their mode to <i>queued</i>.");
|
||
|
m_paResume->setWhatsThis(tmp);
|
||
|
|
||
|
tmp = i18n("<b>Pause</b> button stops selected transfers\n" "and sets their mode to <i>delayed</i>.");
|
||
|
m_paPause->setWhatsThis(tmp);
|
||
|
|
||
|
tmp = i18n("<b>Delete</b> button removes selected transfers\n" "from the list.");
|
||
|
m_paDelete->setWhatsThis(tmp);
|
||
|
|
||
|
tmp = i18n("<b>Restart</b> button is a convenience button\n" "that simply does Pause and Resume.");
|
||
|
m_paRestart->setWhatsThis(tmp);
|
||
|
|
||
|
tmp = i18n("<b>Queued</b> button sets the mode of selected\n" "transfers to <i>queued</i>.\n" "\n" "It is a radio button -- you can choose between\n" "three modes.");
|
||
|
m_paQueue->setWhatsThis(tmp);
|
||
|
|
||
|
tmp = i18n("<b>Scheduled</b> button sets the mode of selected\n" "transfers to <i>scheduled</i>.\n" "\n" "It is a radio button -- you can choose between\n" "three modes.");
|
||
|
m_paTimer->setWhatsThis(tmp);
|
||
|
|
||
|
tmp = i18n("<b>Delayed</b> button sets the mode of selected\n" "transfers to <i>delayed</i>." "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("<b>Preferences</b> 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("<b>Log window</b> 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("<b>Paste transfer</b> 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("<b>Expert mode</b> 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" "<b>Important!</b>\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("<b>Use last folder</b> 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("<b>Auto disconnect</b> 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" "<b>Important!</b>\n" "Also turn on the expert mode when you want KGet\n" "to disconnect without asking.");
|
||
|
m_paAutoDisconnect->setWhatsThis(tmp);
|
||
|
|
||
|
tmp = i18n("<b>Auto shutdown</b> 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" "<b>Important!</b>\n" "Also turn on the expert mode when you want KGet\n" "to quit without asking.");
|
||
|
m_paAutoShutdown->setWhatsThis(tmp);
|
||
|
|
||
|
tmp = i18n("<b>Offline mode</b> 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("<b>Auto paste</b> 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);
|
||
|
|
||
13 years ago
|
tmp = i18n("<b>Drop target</b> 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.");
|
||
15 years ago
|
m_paDropTarget->setWhatsThis(tmp);
|
||
|
/*
|
||
|
tmp = i18n("<b>Dock widget</b> 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("<b>Normal window</b> button sets\n" "\n" "the window style to normal window");
|
||
|
m_paNormal->setWhatsThis(tmp);
|
||
|
*/
|
||
|
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotConfigureToolbars()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
12 years ago
|
saveMainWindowSettings( TDEGlobal::config(), "MainWindow" );
|
||
15 years ago
|
KEditToolbar edit(factory());
|
||
14 years ago
|
connect(&edit, TQT_SIGNAL( newToolbarConfig() ), this, TQT_SLOT( slotNewToolbarConfig() ));
|
||
15 years ago
|
edit.exec();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotNewToolbarConfig()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
createGUI("kgetui.rc");
|
||
12 years ago
|
applyMainWindowSettings( TDEGlobal::config(), "MainWindow" );
|
||
15 years ago
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotImportTextFile()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
14 years ago
|
TQString tmpFile;
|
||
|
TQString list;
|
||
15 years ago
|
int i, j;
|
||
|
|
||
|
KURL filename = KFileDialog::getOpenURL(ksettings.lastDirectory);
|
||
|
if (!filename.isValid())
|
||
|
return;
|
||
|
|
||
12 years ago
|
if (TDEIO::NetAccess::download(filename, tmpFile, this)) {
|
||
15 years ago
|
list = kFileToString(tmpFile);
|
||
12 years ago
|
TDEIO::NetAccess::removeTempFile(tmpFile);
|
||
15 years ago
|
} else
|
||
|
list = kFileToString(filename.path()); // file not accessible -> give error message
|
||
|
|
||
|
i = 0;
|
||
13 years ago
|
while ((j = list.find('\n', i)) != -1) {
|
||
14 years ago
|
TQString newtransfer = list.mid(i, j - i);
|
||
15 years ago
|
addTransfer(newtransfer);
|
||
|
i = j + 1;
|
||
|
}
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotImportTransfers()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
readTransfers(true);
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::readTransfers(bool ask_for_name)
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::readTransfersEx(const KURL & file)
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotExportTransfers()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
writeTransfers(true);
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::writeTransfers(bool ask_for_name)
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
14 years ago
|
TQString str;
|
||
|
TQString txt;
|
||
15 years ago
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::writeLog()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << "Writing log to file : " << logFileName.ascii() << endl;
|
||
|
#endif
|
||
|
|
||
|
|
||
|
kCStringToFile(logWindow->getText().local8Bit(), logFileName, false, false);
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotQuit()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
Transfer *item;
|
||
|
TransferIterator it(myTransferList);
|
||
|
|
||
|
log(i18n("Quitting..."));
|
||
|
|
||
|
for (; it.current(); ++it) {
|
||
|
item = it.current();
|
||
13 years ago
|
if (item->getStatus() == Transfer::ST_RUNNING && !ksettings.b_expertMode) {
|
||
15 years ago
|
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();
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotResumeCurrent()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotPauseCurrent()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotRestartCurrent()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotDeleteCurrent()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
m_paDelete->setEnabled(false);
|
||
|
m_paPause->setEnabled(false);
|
||
|
update();
|
||
|
TransferIterator it(myTransferList);
|
||
14 years ago
|
TQValueList<TQGuardedPtr<Transfer> > selectedItems;
|
||
|
TQStringList itemNames;
|
||
15 years ago
|
|
||
|
while (it.current()) {
|
||
|
if (it.current()->isSelected()) {
|
||
14 years ago
|
selectedItems.append( TQGuardedPtr<Transfer>( it.current() ));
|
||
15 years ago
|
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(),
|
||
14 years ago
|
TQString("multiple_delete_transfer"))
|
||
15 years ago
|
!= KMessageBox::Continue)
|
||
|
return; // keep 'em
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (KMessageBox::warningContinueCancel(this, i18n("Are you sure you want to delete this transfer?"),
|
||
|
i18n("Question"), KStdGuiItem::del(),
|
||
14 years ago
|
TQString("delete_transfer"))
|
||
15 years ago
|
!= 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
|
||
14 years ago
|
// we used a TQGuardedPtr :)
|
||
15 years ago
|
|
||
|
int transferFinishedMeanwhile = 0;
|
||
14 years ago
|
TQValueListConstIterator<TQGuardedPtr<Transfer> > lit = selectedItems.begin();;
|
||
15 years ago
|
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 ),
|
||
13 years ago
|
TQString(), "completedBeforeDeletion" );
|
||
15 years ago
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::stopAll()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
log(i18n("Stopping all jobs"), false);
|
||
|
|
||
|
TransferIterator it(myTransferList);
|
||
13 years ago
|
Transfer::TransferStatus Status;
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
13 years ago
|
Status = it.current()->getStatus();
|
||
|
if (Status == Transfer::ST_TRYING || Status == Transfer::ST_RUNNING)
|
||
15 years ago
|
it.current()->slotStop();
|
||
|
}
|
||
|
slotUpdateActions();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotQueueCurrent()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotTimerCurrent()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
|
||
|
TransferIterator it(myTransferList);
|
||
|
|
||
|
for (; it.current(); ++it)
|
||
|
if (it.current()->isSelected())
|
||
|
it.current()->slotRequestSchedule();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotDelayCurrent()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
TransferIterator it(myTransferList);
|
||
|
|
||
|
for (; it.current(); ++it)
|
||
|
if (it.current()->isSelected())
|
||
|
it.current()->slotRequestDelay();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotOpenTransfer()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
14 years ago
|
TQString newtransfer;
|
||
15 years ago
|
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()) {
|
||
13 years ago
|
KMessageBox::error(this, i18n("Malformed URL:\n%1").arg(newtransfer), i18n("Error"));
|
||
15 years ago
|
ok = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
addTransfer(newtransfer);
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotCheckClipboard()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
13 years ago
|
TQString clipData = TQApplication::clipboard()->text( TQClipboard::Clipboard ).stripWhiteSpace();
|
||
15 years ago
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotPasteTransfer()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
14 years ago
|
TQString newtransfer;
|
||
15 years ago
|
|
||
13 years ago
|
newtransfer = TQApplication::clipboard()->text();
|
||
15 years ago
|
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.
|
||
12 years ago
|
void TDEMainWidget::addTransferEx(const KURL& url, const KURL& destFile)
|
||
15 years ago
|
{
|
||
|
#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
|
||
14 years ago
|
TQString destDir = getSaveDirectoryFor( url.fileName() );
|
||
15 years ago
|
bool b_expertMode = ksettings.b_expertMode;
|
||
|
bool bDestisMalformed = true;
|
||
|
|
||
|
while (bDestisMalformed)
|
||
|
{
|
||
|
if (!b_expertMode) {
|
||
|
// open the filedialog for confirmation
|
||
13 years ago
|
KFileDialog dlg( destDir, TQString(),
|
||
15 years ago
|
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());
|
||
|
|
||
14 years ago
|
if ( dlg.exec() == TQDialog::Rejected )
|
||
15 years ago
|
{
|
||
|
#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
|
||
12 years ago
|
if(TDEIO::NetAccess::exists(destURL, false, this))
|
||
15 years ago
|
{
|
||
13 years ago
|
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") )
|
||
15 years ago
|
== 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
|
||
12 years ago
|
// really want to delete (at least tdehtml does)
|
||
12 years ago
|
if(TDEIO::NetAccess::exists(destURL, false, this))
|
||
15 years ago
|
SafeDelete::deleteFile( destURL );
|
||
|
}
|
||
|
|
||
|
// create a new transfer item
|
||
|
Transfer *item = myTransferList->addTransfer(url, destURL);
|
||
13 years ago
|
KNotifyClient::event(kdock->winId(), "added", i18n("<i>%1</i> has been added.").arg(url.prettyURL()));
|
||
15 years ago
|
item->updateAll(); // update the remaining fields
|
||
|
|
||
|
if (ksettings.b_showIndividual)
|
||
|
item->showIndividual();
|
||
|
|
||
|
myTransferList->clearSelection();
|
||
|
|
||
|
checkQueue();
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::addTransfers( const KURL::List& src, const TQString& destDir )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQValueList<KURLPair> urls_orig;
|
||
15 years ago
|
|
||
|
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 );
|
||
14 years ago
|
TQString fileName = urls_orig.first().src.fileName();
|
||
15 years ago
|
|
||
|
// 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 );
|
||
12 years ago
|
if(TDEIO::NetAccess::exists(destURL, false, this))
|
||
15 years ago
|
{
|
||
13 years ago
|
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") )
|
||
15 years ago
|
== 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;
|
||
14 years ago
|
TQValueList<KURLPair>::Iterator it;
|
||
|
TQValueList<KURLPair> urls;
|
||
15 years ago
|
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;
|
||
14 years ago
|
if ( destDir.isEmpty() || !TQFileInfo( destDir ).isDir() )
|
||
15 years ago
|
{
|
||
|
if ( !destDir.isEmpty() )
|
||
|
dest.setPath( destDir );
|
||
|
else
|
||
|
dest.setPath( getSaveDirectoryFor( src.first().fileName() ) );
|
||
|
|
||
|
// ask in any case, when destDir is empty
|
||
14 years ago
|
if ( destDir.isEmpty() || !TQFileInfo( dest.path() ).isDir() )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString dir = KFileDialog::getExistingDirectory( dest.path() );
|
||
15 years ago
|
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();
|
||
12 years ago
|
TDEIO::RenameDlg_Result result;
|
||
15 years ago
|
while ( it != urls.end() )
|
||
|
{
|
||
|
|
||
|
if ( !sanityChecksSuccessful( (*it).src ) )
|
||
|
{
|
||
|
it = urls.erase( it );
|
||
|
continue; // shouldn't we notify the user??
|
||
|
}
|
||
|
|
||
|
(*it).dest = dest;
|
||
14 years ago
|
TQString fileName = (*it).src.fileName();
|
||
15 years ago
|
if ( fileName.isEmpty() ) // simply use the full url as filename
|
||
|
fileName = KURL::encode_string_no_slash( (*it).src.prettyURL() );
|
||
|
|
||
|
(*it).dest.setFileName( fileName );
|
||
|
|
||
12 years ago
|
if( TDEIO::NetAccess::exists((*it).dest, false, this))
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString newdest;
|
||
15 years ago
|
if (skip_all)
|
||
12 years ago
|
result = TDEIO::R_SKIP;
|
||
15 years ago
|
else if( overwrite_all )
|
||
12 years ago
|
result = TDEIO::R_OVERWRITE;
|
||
15 years ago
|
else
|
||
|
{
|
||
14 years ago
|
TQFileInfo finfo( (*it).dest.path() );
|
||
|
TQString caption = i18n( "File Already exists" ) + " - KGet";
|
||
12 years ago
|
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());
|
||
15 years ago
|
}
|
||
|
switch (result)
|
||
|
{
|
||
12 years ago
|
case TDEIO::R_RENAME:
|
||
15 years ago
|
(*it).dest = KURL::fromPathOrURL( newdest );
|
||
|
break;
|
||
12 years ago
|
case TDEIO::R_OVERWRITE_ALL:
|
||
15 years ago
|
overwrite_all = true; //fall through
|
||
12 years ago
|
case TDEIO::R_OVERWRITE:
|
||
15 years ago
|
urlsToDelete.append( (*it).dest );
|
||
|
break;
|
||
12 years ago
|
case TDEIO::R_AUTO_SKIP:
|
||
15 years ago
|
skip_all = true;
|
||
12 years ago
|
case TDEIO::R_SKIP: //fall through
|
||
15 years ago
|
it = urls.erase( it );
|
||
|
continue;
|
||
|
break;
|
||
|
default: // Cancel, ask again for directory
|
||
|
dir_accepted = false;
|
||
|
}
|
||
|
if ( !dir_accepted )
|
||
|
break;
|
||
12 years ago
|
} // if(TDEIO::NetAccess::exists
|
||
15 years ago
|
++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();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::addTransfer(const TQString& src)
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
if ( src.isEmpty() )
|
||
|
return;
|
||
|
|
||
|
addTransferEx( KURL::fromPathOrURL( src ) );
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::checkQueue()
|
||
15 years ago
|
{
|
||
|
#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) {
|
||
13 years ago
|
status = it.current()->getStatus();
|
||
15 years ago
|
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();
|
||
13 years ago
|
isRunning = (item->getStatus() == Transfer::ST_RUNNING) || ((item->getStatus() == Transfer::ST_TRYING));
|
||
15 years ago
|
|
||
13 years ago
|
isQuequed = (item->getMode() == Transfer::MD_QUEUED || item->getMode() == Transfer::MD_NEW);
|
||
15 years ago
|
|
||
|
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();
|
||
13 years ago
|
if (item->getMode() == Transfer::MD_NEW && item->getStatus() == Transfer::ST_STOPPED)
|
||
15 years ago
|
{
|
||
|
item->checkCache();
|
||
|
}
|
||
|
}
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotAnimTimeout()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
bool isTransfer;
|
||
|
|
||
|
animCounter++;
|
||
|
if (animCounter == myTransferList->getPhasesNum()) {
|
||
|
//updateStatusBar();
|
||
|
animCounter = 0;
|
||
|
}
|
||
|
// update status of all items of transferList
|
||
13 years ago
|
isTransfer = myTransferList->updateStatus(animCounter);
|
||
15 years ago
|
|
||
|
//if (this->isVisible()) {
|
||
|
updateStatusBar();
|
||
|
//}
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugOut << endl;
|
||
|
#endif
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotTransferTimeout()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
Transfer *item;
|
||
|
TransferIterator it(myTransferList);
|
||
|
|
||
|
bool flag = false;
|
||
|
|
||
|
for (; it.current(); ++it) {
|
||
|
item = it.current();
|
||
13 years ago
|
if (item->getMode() == Transfer::MD_SCHEDULED && item->getStartTime() <= TQDateTime::currentDateTime()) {
|
||
13 years ago
|
item->setMode(Transfer::MD_QUEUED);
|
||
15 years ago
|
flag = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (flag) {
|
||
|
checkQueue();
|
||
|
}
|
||
|
|
||
13 years ago
|
if (ksettings.b_autoDisconnect && ksettings.b_timedDisconnect && ksettings.disconnectTime <= TQTime::currentTime() && ksettings.disconnectDate == TQDate::currentDate()) {
|
||
15 years ago
|
onlineDisconnect();
|
||
|
}
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotAutosaveTimeout()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
writeTransfers();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotStatusChanged(Transfer * item, int _operation)
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
switch (_operation) {
|
||
|
|
||
|
case Transfer::OP_FINISHED:
|
||
|
{
|
||
14 years ago
|
TQString srcurl = item->getSrc().prettyURL();
|
||
15 years ago
|
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
|
||
|
{
|
||
13 years ago
|
KNotifyClient::event(kdock->winId(), "finished", i18n("<i>%1</i> successfully downloaded.").arg(srcurl));
|
||
15 years ago
|
}
|
||
|
|
||
|
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:
|
||
13 years ago
|
case Transfer::OP_QUEUED:
|
||
15 years ago
|
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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::dragEnterEvent(TQDragEnterEvent * event)
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
14 years ago
|
event->accept(KURLDrag::canDecode(event) || TQTextDrag::canDecode(event));
|
||
15 years ago
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::dropEvent(TQDropEvent * event)
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
KURL::List list;
|
||
14 years ago
|
TQString str;
|
||
15 years ago
|
|
||
|
if (KURLDrag::decode(event, list)) {
|
||
|
addTransfers(list);
|
||
14 years ago
|
} else if (TQTextDrag::decode(event, str)) {
|
||
15 years ago
|
addTransfer(str);
|
||
|
}
|
||
|
sDebugOut << endl;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotCopyToClipboard()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
Transfer *item = (Transfer *) myTransferList->currentItem();
|
||
|
|
||
|
if (item) {
|
||
14 years ago
|
TQString url = item->getSrc().url();
|
||
13 years ago
|
TQClipboard *cb = TQApplication::clipboard();
|
||
13 years ago
|
cb->setText( url, TQClipboard::Selection );
|
||
|
cb->setText( url, TQClipboard::Clipboard);
|
||
15 years ago
|
myTransferList->clearSelection();
|
||
|
}
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotMoveToBegin()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
myTransferList->moveToBegin((Transfer *) myTransferList->currentItem());
|
||
|
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotMoveToEnd()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
myTransferList->moveToEnd((Transfer *) myTransferList->currentItem());
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotOpenIndividual()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
Transfer *item = (Transfer *) myTransferList->currentItem();
|
||
|
if (item)
|
||
|
item->showIndividual();
|
||
|
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEMainWidget::queryClose()
|
||
15 years ago
|
{
|
||
|
if( kapp->sessionSaving())
|
||
|
return true;
|
||
|
hide();
|
||
|
return false;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::setAutoSave()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
autosaveTimer->stop();
|
||
|
if (ksettings.b_autoSave) {
|
||
|
autosaveTimer->start(ksettings.autoSaveInterval * 60000);
|
||
|
}
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::setAutoDisconnect()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
// disable action when we are connected permanently
|
||
|
m_paAutoDisconnect->setEnabled(ksettings.connectionType != PERMANENT);
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotPreferences()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
if ( !prefDlg )
|
||
|
prefDlg = new DlgPreferences(this);
|
||
|
|
||
|
prefDlg->show();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotConfigureNotifications()
|
||
15 years ago
|
{
|
||
|
KNotifyDialog::configure(this);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotToggleLogWindow()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
b_viewLogWindow = !b_viewLogWindow;
|
||
|
if (b_viewLogWindow)
|
||
|
logWindow->show();
|
||
|
else
|
||
|
logWindow->hide();
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotToggleAnimation()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotToggleOfflineMode()
|
||
15 years ago
|
{
|
||
|
#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."));
|
||
13 years ago
|
setCaption(TQString(), false);
|
||
15 years ago
|
m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_on"));
|
||
|
}
|
||
|
|
||
|
m_paOfflineMode->setChecked(ksettings.b_offline);
|
||
|
|
||
|
|
||
|
slotUpdateActions();
|
||
|
checkQueue();
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotToggleExpertMode()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotToggleUseLastDir()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotToggleAutoDisconnect()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotToggleAutoShutdown()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotToggleAutoPaste()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotToggleDropTarget()
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotKonquerorIntegration()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
bool bIsKonquiEnable=!ksettings.b_KonquerorIntegration;
|
||
|
ksettings.b_KonquerorIntegration=!ksettings.b_KonquerorIntegration;
|
||
12 years ago
|
TDEConfig cfg("konquerorrc", false, false);
|
||
15 years ago
|
cfg.setGroup("HTML Settings");
|
||
14 years ago
|
cfg.writePathEntry("DownloadManager",TQString((bIsKonquiEnable)?"kget":""));
|
||
15 years ago
|
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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotPopupMenu(Transfer * item)
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
// select current item
|
||
|
myTransferList->setCurrentItem(item);
|
||
|
|
||
|
// set action properties
|
||
|
slotUpdateActions();
|
||
|
|
||
|
// popup transfer menu at the position
|
||
14 years ago
|
TQWidget *menu = guiFactory()->container("transfer",this);
|
||
|
((TQPopupMenu *) menu)->popup(TQCursor::pos());
|
||
15 years ago
|
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::setListFont()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
myTransferList->setFont(ksettings.listViewFont);
|
||
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotUpdateActions()
|
||
15 years ago
|
{
|
||
|
#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) {
|
||
13 years ago
|
switch (item->getStatus()) {
|
||
15 years ago
|
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
|
||
13 years ago
|
sDebug << "STATUS IS stopped" << item->getStatus() << endl;
|
||
15 years ago
|
#endif
|
||
|
break;
|
||
|
case Transfer::ST_FINISHED:
|
||
|
m_paResume->setEnabled(false);
|
||
|
m_paPause->setEnabled(false);
|
||
|
m_paRestart->setEnabled(false);
|
||
|
break;
|
||
|
|
||
|
|
||
|
} //end switch
|
||
|
|
||
13 years ago
|
} else if (item->getStatus() != first_item->getStatus()) {
|
||
15 years ago
|
// 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);
|
||
13 years ago
|
if (item->getStatus() != Transfer::ST_FINISHED) {
|
||
15 years ago
|
m_paQueue->setEnabled(true);
|
||
|
m_paTimer->setEnabled(true);
|
||
|
m_paDelay->setEnabled(true);
|
||
|
|
||
|
switch (item->getMode()) {
|
||
13 years ago
|
case Transfer::MD_QUEUED:
|
||
15 years ago
|
#ifdef _DEBUG
|
||
13 years ago
|
sDebug << "....................THE MODE IS MD_QUEUED " << item->getMode() << endl;
|
||
15 years ago
|
#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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::updateStatusBar()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
|
||
|
Transfer *item;
|
||
14 years ago
|
TQString tmpstr;
|
||
15 years ago
|
|
||
|
int totalFiles = 0;
|
||
12 years ago
|
TDEIO::filesize_t totalSize = 0;
|
||
15 years ago
|
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();
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
statusBar()->changeItem(i18n(" Transfers: %1 ").arg(myTransferList->childCount()), ID_TOTAL_TRANSFERS);
|
||
|
statusBar()->changeItem(i18n(" Files: %1 ").arg(totalFiles), ID_TOTAL_FILES);
|
||
12 years ago
|
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);
|
||
15 years ago
|
//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) {
|
||
13 years ago
|
tmpstr = i18n("<b>Transfers:</b> %1 ").arg(myTransferList->childCount()) +
|
||
|
i18n("<br /><b>Files:</b> %1 ").arg(totalFiles) +
|
||
12 years ago
|
i18n("<br /><b>Size:</b> %1 ").arg(TDEIO::convertSize(totalSize)) +
|
||
|
i18n("<br /><b>Time:</b> %1 ").arg(TDEIO::convertSeconds(remTime)) +
|
||
|
i18n("<br /><b>Speed:</b> %1/s").arg(TDEIO::convertSize(totalSpeed));
|
||
15 years ago
|
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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::onlineDisconnect()
|
||
15 years ago
|
{
|
||
|
#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..."));
|
||
14 years ago
|
system(TQFile::encodeName(ksettings.disconnectCommand));
|
||
15 years ago
|
|
||
|
#ifdef _DEBUG
|
||
|
sDebugOut << endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotCheckConnection()
|
||
15 years ago
|
{
|
||
|
#ifdef _DEBUG
|
||
|
//sDebugIn << endl;
|
||
|
#endif
|
||
|
bool old = b_connected;
|
||
|
checkOnline();
|
||
|
if (b_connected != old) {
|
||
|
if (b_connected) {
|
||
|
log(i18n("We are online."));
|
||
13 years ago
|
setCaption(TQString(), false);
|
||
15 years ago
|
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
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEMainWidget::checkOnline()
|
||
15 years ago
|
{
|
||
|
#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 << "<<<<Leaving -> 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 */
|
||
12 years ago
|
void TDEMainWidget::customEvent(TQCustomEvent * _e)
|
||
15 years ago
|
{
|
||
|
#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
|
||
|
}
|
||
|
|
||
12 years ago
|
TQString TDEMainWidget::getSaveDirectoryFor( const TQString& filename ) const
|
||
15 years ago
|
{
|
||
|
// first set destination directory to current directory ( which is also last used )
|
||
14 years ago
|
TQString destDir = ksettings.lastDirectory;
|
||
15 years ago
|
|
||
|
if (!ksettings.b_useLastDir) {
|
||
|
// check wildcards for default directory
|
||
|
DirList::Iterator it;
|
||
|
for (it = ksettings.defaultDirList.begin(); it != ksettings.defaultDirList.end(); ++it) {
|
||
14 years ago
|
TQRegExp rexp((*it).extRegexp);
|
||
15 years ago
|
|
||
|
rexp.setWildcard(true);
|
||
|
|
||
|
if ((rexp.search( filename )) != -1) {
|
||
|
destDir = (*it).defaultDir;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return destDir;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEMainWidget::sanityChecksSuccessful( const KURL& url )
|
||
15 years ago
|
{
|
||
|
if (!url.isValid() || !KProtocolInfo::supportsReading( url ) )
|
||
|
{
|
||
|
if (!ksettings.b_expertMode)
|
||
13 years ago
|
KMessageBox::error(this, i18n("Malformed URL:\n%1").arg(url.prettyURL()), i18n("Error"));
|
||
15 years ago
|
|
||
|
return false;
|
||
|
}
|
||
|
// if we find this URL in the list
|
||
13 years ago
|
Transfer *transfer = myTransferList->find( url );
|
||
15 years ago
|
if ( transfer )
|
||
|
{
|
||
13 years ago
|
if ( transfer->getStatus() != Transfer::ST_FINISHED )
|
||
15 years ago
|
{
|
||
|
if ( !ksettings.b_expertMode )
|
||
|
{
|
||
13 years ago
|
KMessageBox::error(this, i18n("Already saving URL\n%1").arg(url.prettyURL()), i18n("Error"));
|
||
15 years ago
|
}
|
||
|
|
||
|
transfer->showIndividual();
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
else // transfer is finished, ask if we want to download again
|
||
|
{
|
||
|
if ( ksettings.b_expertMode ||
|
||
13 years ago
|
(KMessageBox::questionYesNo(this, i18n("Already saved URL\n%1\nDownload again?").arg(url.prettyURL()),i18n("Question"),i18n("Download Again"),KStdGuiItem::cancel() )
|
||
15 years ago
|
== 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") {
|
||
13 years ago
|
// KMessageBox::error(this, i18n("File protocol not accepted!\n%1").arg(url.prettyURL()), i18n("Error"));
|
||
15 years ago
|
// #ifdef _DEBUG
|
||
|
// sDebugOut << endl;
|
||
|
// #endif
|
||
|
// return false;
|
||
|
// }
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEMainWidget::isDropTargetVisible() const
|
||
15 years ago
|
{
|
||
|
return m_showDropTarget;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::setDropTargetVisible( bool setVisible )
|
||
15 years ago
|
{
|
||
|
if ( setVisible != isDropTargetVisible() )
|
||
|
{
|
||
|
m_paDropTarget->activate();
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::setOfflineMode( bool offline )
|
||
15 years ago
|
{
|
||
|
if ( ksettings.b_offlineMode != offline )
|
||
|
slotToggleOfflineMode();
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEMainWidget::isOfflineMode() const
|
||
15 years ago
|
{
|
||
|
return ksettings.b_offlineMode;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::activateDropTarget()
|
||
15 years ago
|
{
|
||
|
setDropTargetVisible( true );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEMainWidget::slotShowMenubar()
|
||
15 years ago
|
{
|
||
|
if(m_menubarAction->isChecked())
|
||
|
menuBar()->show();
|
||
|
else
|
||
|
menuBar()->hide();
|
||
|
}
|
||
|
|
||
|
#include "kmainwidget.moc"
|