/* Copyright 2003 Rikard Björklind, Mikael Gransell, Arsenij Vodjanov This file is part of dc-qt. dc-qt 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. dc-qt 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 dc-qt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mainwdgt.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "dc_settings.h" #include "preferences_dlg.h" #include "searchwdgt.h" #include "pixmaps.h" #include "config.h" #include "helpwindow.h" #include "dc_hub.h" #include "dctc_hub.h" #include "transfer_widget.h" #include "hubwdgt.h" #include "status_monitor.h" // include this file last! #include "preview_dialog.h" #ifdef _DEBUG #include using namespace std; #endif // Some globals DebugDlg* debugWin; dc_settings settings; Pixmap *pixmaps; MainWdgt* MainWdgt::instance; MainWdgt::MainWdgt( QWidget* parent, const char* name ) : QMainWindow( parent, name ) { progressDlg = 0; preview_dlg = 0; switch(settings.init()) { case dc_settings::SUCCESS: break; case dc_settings::NO_SETTINGS: showPreferences(); break; case dc_settings::ERROR_LOADING_PREFS: QMessageBox::critical(this, "Error", "Error loading preferences file.", "Ok"); break; // case dc_settings::ERROR_LOADING_FAVOURITES: // QMessageBox::critical(this, "Error", "Error loading the favourites file.","Ok"); // break; default: // This should not happen break; } debugWin = new DebugDlg(); /* show() moved to debugdlg.cc -#ifdef _DEBUG debugWin->show(); -#endif */ QFont font; font.fromString( settings.get_setting("font") ); QApplication::setFont(font,true); // load window pos and size wnd_setting wndset(settings.get_setting("wndset_main")); if (wndset.isValid()) { move(QPoint(wndset.x(), wndset.y())); resize(wndset.w(), wndset.h()); } pixmaps = new Pixmap; // Set the application icon setIcon( pixmaps->getIcon() ); // QVBox *mainbox = new QVBox(this, "mainvbox"); mainbox = new QSplitter(Qt::Vertical,this,"mainsplitter"); hubTabs = new QTabWidget( mainbox, "Hub Tabs" ); QObject::connect(hubTabs, SIGNAL(currentChanged(QWidget*)), this, SLOT(selectHub(QWidget*))); // Create status monitor instance status_monitor *sm = new status_monitor(0, "StatusMon"); sm->hide(); // connect status mon and main window QObject::connect(sm, SIGNAL(sig_hide_ui()), this, SLOT(hide())); QObject::connect(sm, SIGNAL(sig_show_ui()), this, SLOT(show())); QObject::connect(this, SIGNAL(sig_hub_opened()), sm, SLOT(hub_opened())); QObject::connect(this, SIGNAL(sig_hub_closed()), sm, SLOT(hub_closed())); // Create transfer widget transferWidget = new transfer_widget(mainbox, "Transfers Window"); // connect main widget and transfer widget QObject::connect(this, SIGNAL(sig_hub_opened()), transferWidget, SLOT(hub_opened())); // connect transfer widget to status mon QObject::connect(transferWidget, SIGNAL(sig_ul_added()), sm, SLOT(ul_added())); QObject::connect(transferWidget, SIGNAL(sig_ul_removed()), sm, SLOT(ul_removed())); QObject::connect(transferWidget, SIGNAL(sig_gdl_active()), sm, SLOT(gdl_active())); QObject::connect(transferWidget, SIGNAL(sig_gdl_queued()), sm, SLOT(gdl_queued())); QObject::connect(transferWidget, SIGNAL(sig_gdl_added(const unsigned int, const QString &, const unsigned long)), sm, SLOT(gdl_added(const unsigned int, const QString &, const unsigned long))); QObject::connect(transferWidget, SIGNAL(sig_gdl_removed(const unsigned int)), sm, SLOT(gdl_removed(const unsigned int))); QPopupMenu* file = new QPopupMenu( this, "File menu" ); QPopupMenu* help = new QPopupMenu( this, "Help menu" ); // Set our popupmenus in the main window menubar menuBar()->insertItem( "&Actions", file ); #ifdef _DEBUG QPopupMenu *debug = new QPopupMenu(this,"Debug menu"); menuBar()->insertItem("&Debug",debug); debug->insertItem("Send DCTC command",this,SLOT(sendDCTCCommand())); #endif menuBar()->insertItem( "&Help", help ); // common for all (so far) themes QIconSet previewIcon(pixmaps->getPreview()); // Construct icon using default pixmaps QIconSet::setIconSize(QIconSet::Large,QSize(22,22)); QIconSet newIcon(pixmaps->getNew()); QIconSet closeIcon(pixmaps->getClose()); QIconSet connectIcon(pixmaps->getConnect()); QIconSet disIcon(pixmaps->getDisconnect()); QIconSet searchIcon(pixmaps->getSearch()); QIconSet configureIcon(pixmaps->getConfigure()); QIconSet exitIcon(pixmaps->getExit()); QIconSet reshareIcon(pixmaps->getReshare()); QIconSet minimodeIcon(pixmaps->getMiniicon()); // load name of user-selected iconset QString iconset_name = settings.get_setting("tool_iconset"); // if icon set selected in prefs is not default, reload with correct pixmaps if (iconset_name == "IHQ") { newIcon.reset(pixmaps->getNew_ihq(), QIconSet::Automatic); closeIcon.reset(pixmaps->getClose_ihq(), QIconSet::Automatic); connectIcon.reset(pixmaps->getConnect_ihq(), QIconSet::Automatic); disIcon.reset(pixmaps->getDisconnect_ihq(), QIconSet::Automatic); searchIcon.reset(pixmaps->getSearch_ihq(), QIconSet::Automatic); configureIcon.reset(pixmaps->getConfigure_ihq(), QIconSet::Automatic); exitIcon.reset(pixmaps->getExit_ihq(), QIconSet::Automatic); reshareIcon.reset(pixmaps->getReshare_ihq(), QIconSet::Automatic); minimodeIcon.reset(pixmaps->getMiniicon_ihq(), QIconSet::Automatic); } aNewHub = new QAction("New Hub", newIcon, "&New hub", CTRL+Key_N, this, "newhubtab"); aNewHub->setToolTip("Creates a new hub tab"); aConnect = new QAction("Connect", connectIcon, "&Connect", CTRL+Key_C, this, "connect"); aConnect->setToolTip("Opens the connection dialog"); aReshare = new QAction("Reshare",reshareIcon,"&Reshare",CTRL+Key_R,this,"reshare"); aReshare->setToolTip("Rebuilds the shared file database"); aSearch = new QAction("Search", searchIcon, "&Search", CTRL+Key_S, this, "search"); aSearch->setToolTip("Opens a search dialog. There is one search dialog per hub."); aMinimode = new QAction("Icon-Mode", minimodeIcon, "&Icon-Mode", CTRL+Key_I,this, "iconmode"); aMinimode->setToolTip("Runs DC-Qt in Icon-mode"); aPreview = new QAction("Preview", previewIcon, "Pre&view", CTRL+Key_V, this, "preview"); aPreview->setToolTip("Opens the media preview dialog."); aDisconnect = new QAction("Disconnect", disIcon, "&Disconnect", CTRL+Key_D, this, "disconnect"); aDisconnect->setToolTip("Disconnects the active hub tab"); aCloseHub = new QAction("Close Hub", closeIcon, "C&lose hub", CTRL+Key_X, this, "closehubtab"); aCloseHub->setToolTip("Deletes the selected hub tab"); aConfig = new QAction("Preferences", configureIcon, "&Preferences", CTRL+Key_P, this, "prefs"); aConfig->setToolTip("Opens the preferences dialog."); aExit = new QAction("Quit", exitIcon, "&Quit", CTRL+Key_Q,this, "quit"); aExit->setToolTip("Quits the program"); QObject::connect(aNewHub, SIGNAL(activated()), this, SLOT(newHubTab())); QObject::connect(aCloseHub, SIGNAL(activated()), this, SLOT(closeHubTab())); QObject::connect(aConnect, SIGNAL(activated()), this, SLOT(connectHub())); QObject::connect(aDisconnect, SIGNAL(activated()), this, SLOT(disHub())); QObject::connect(aReshare,SIGNAL(activated()),this,SLOT(reshare())); QObject::connect(aSearch, SIGNAL(activated()), this, SLOT(searchHub())); QObject::connect(aConfig, SIGNAL(activated()), this, SLOT(showPreferences())); QObject::connect(aMinimode, SIGNAL(activated()), sm, SLOT(slot_hide_ui())); QObject::connect(aPreview, SIGNAL(activated()), this, SLOT(show_preview_dialog())); QObject::connect(aExit, SIGNAL(activated()), this, SLOT(close())); aNewHub->addTo(file); aCloseHub->addTo(file); file->insertSeparator(); aReshare->addTo(file); aSearch->addTo(file); aPreview->addTo(file); aMinimode->addTo(file); aConnect->addTo(file); aDisconnect->addTo(file); aDisconnect->setEnabled(false); file->insertSeparator(); aConfig->addTo(file); aExit->addTo(file); QAction *aHelpContents = new QAction("Contents","&Contents",Key_F1,this,"helpcontentsaction"); QObject::connect(aHelpContents,SIGNAL(activated()),this,SLOT(displayHelp())); aHelpContents->addTo(help); help->insertItem( "Newest &version",this,SLOT(checkVersion())); help->insertItem( "&About", this, SLOT(displayAbout()) ); help->insertItem( "About &Qt",this, SLOT(displayAboutQt()) ); newHubTab(); // Add all things to our main window setCaption( "dc-qt " VERSION ); setCentralWidget( mainbox ); // Create the toolbar QToolBar * tools = new QToolBar( this, "toolbar" ); tools->setHorizontallyStretchable(true); //tools->setHorizontallyStretchable(false); tools->setLabel( "Tools" ); setUsesBigPixmaps(true); setUsesTextLabel(true); aNewHub->addTo(tools); aCloseHub->addTo(tools); tools->addSeparator(); aSearch->addTo(tools); aPreview->addTo(tools); aMinimode->addTo(tools); tools->addSeparator(); aConnect->addTo(tools); aDisconnect->addTo(tools); // aConfig->addTo(tools); aExit->addTo(tools); // tools->boxLayout()->insertStretch(1); // Create the global debugWindow statusBar()->message("Ready.",2000); statusBar()->setSizeGripEnabled(true); // set splitter sizes intlist_setting sslist(settings.get_setting("splitset_main")); mainbox->setSizes(sslist.intlist); instance = this; if(!checkDCTCVersion()) { debugWin->print("DCTC not found!"); QMessageBox::critical(this,"dc-qt Error","DCTC could not be found in your path!\nYou will not be able to connect to any hubs.\nPlease install DCTC (http://ac2i.homelinux.com/dctc/)"); } // YEAH, init URL oper and shit like that here once and for // all, cause we get different things from the site now, not // just the version number if (!recvData.isNull()) recvData.resize(0); current_op = NONE; qInitNetworkProtocols(); urlop = new QUrlOperator( "http://dc-qt.sourceforge.net" ); QObject::connect(urlop,SIGNAL(data(const QByteArray&, QNetworkOperation*)), this,SLOT(wwwxfer_incoming(const QByteArray&, QNetworkOperation*))); QObject::connect(urlop,SIGNAL(finished(QNetworkOperation*)), this,SLOT(wwwxfer_finished(QNetworkOperation*))); if (settings.get_setting("register_session")=="true") register_session(); // check if should register if (settings.get_setting("register_never") != "true") QTimer::singleShot(1000, this, SLOT(register_installation())); cleanDCTCDir(); QTimer::singleShot(1000,this,SLOT( doAutoConnect())); } void MainWdgt::cleanDCTCDir() { if(dc_hub::getNumClients()==0) { QString path = settings.get_home_dir(); path+="/.dctc"; //cerr << "removing " + path + "\n"; debugWin->print("Seems safe to remove " + path + ", removing..."); system( "rm -rf " + path ); } } void MainWdgt::doAutoConnect() { bool firstconnect = true; // DA EViL MiGTHY AUTOCONNECT for(int i=0;i < settings.num_favourites();i++) { QString name,pwd,ip,prof; bool autoc=false; settings.get_favourite(i,name,ip,pwd,autoc,prof); if(autoc) { HubWdgt *h; if(firstconnect) h = (HubWdgt*)hubTabs->currentPage(); else h = newHubTab(); firstconnect = false; h->connect(ip,pwd,prof); } } } void MainWdgt::setHubName(const QString &name, QWidget *wdgt) { hubTabs->changeTab(wdgt,name); } void MainWdgt::showPreferences() { preferences_dlg *pdlg = new preferences_dlg(this,"preferencesdialog",true); pdlg->exec(); delete pdlg; } void MainWdgt::show_preview_dialog() { if (preview_dlg==NULL) { preview_dlg = new preview_dialog(NULL, "Preview Dialog"); preview_dlg->setCaption("Media Preview"); QObject::connect(transferWidget, SIGNAL(sig_gdl_complete(const QString&, const QString&)), preview_dlg, SLOT(slot_add_history_file(const QString&, const QString&))); QObject::connect(transferWidget, SIGNAL(sig_preview_gdl(const QString&, const QString&)), preview_dlg, SLOT(slot_play_file(const QString&, const QString&))); } preview_dlg->show(); } void MainWdgt::displayAbout() { QMessageBox::about(this,"About dcqt","This is dc-qt " VERSION "\ndc-qt is a front end for the direct connect client dctc.\nAuthors:\n\nRikard Björklind (olof@linux.nu)\nMikael Gransell (migr8915@student.uu.se) \nArsenij Vodjanov (estrato@users.sourceforge.net)\n\nhttp://dc-qt.sourceforge.net"); } void MainWdgt::displayAboutQt() { QMessageBox::aboutQt(this); } HubWdgt* MainWdgt::newHubTab() { HubWdgt* hub = new HubWdgt( transferWidget, hubTabs, "hub" ); // Add our new hub hubTabs->addTab( hub, "New Hub" ); // Set the id of our tab so we can remove it later hub->setId( hubTabs->indexOf(hub) ); QObject::connect( hub, SIGNAL(gotName(const QString&, QWidget*)), this, SLOT(setHubName(const QString&, QWidget*))); QObject::connect( hub, SIGNAL(multiSearchResult(const QString&,const QString&,const QString&,const QString&,const QString&)), this, SLOT(dispatchSearchResult(const QString&,const QString&,const QString&,const QString&,const QString&))); QObject::connect ( hub, SIGNAL(disconnected(int)), this, SLOT(hubDisconnected(int))); QObject::connect( hub,SIGNAL(showStatus(const QString&)),this,SLOT(showStatus(const QString&))); QObject::connect(hub,SIGNAL(showProgress(const QString&,const QString&)), this,SLOT(showProgress(const QString&,const QString&))); QObject::connect(hub,SIGNAL(connected(int)),this,SLOT(hubConnected(int ))); hubTabs->showPage(hub); return hub; } void MainWdgt::hubDisconnected(int id) { if(hubTabs->currentPageIndex()==id) { aConnect->setEnabled(true); aDisconnect->setEnabled(false); } statusBar()->message("Hub " + hubTabs->label(id) + " disconnected",3000); emit sig_hub_closed(); } void MainWdgt::hubConnected(int id) { if(hubTabs->currentPageIndex()==id) { aConnect->setEnabled(false); aDisconnect->setEnabled(true); } statusBar()->message("Connected to Hub " + hubTabs->label(id),3000); emit sig_hub_opened(); } void MainWdgt::dispatchSearchResult(const QString& u,const QString& f,const QString& s,const QString& sl,const QString& hubname) { // Find the right hub // estr -- I add a special case for when there is just one tab, so a // search after "connect to running" doesnt get confused by the // hubname. This here case handles multihub search. Normal search is handled // in hubwdgt.cc // update: this was stupid and I fixed it another way, but can't be // arsed to clean out the code // if (hubTabs->count() <= 1) { HubWdgt *w = (HubWdgt*)hubTabs->page(0); if (w!=NULL) { if (hubname.findRev(hubTabs->label(0), -1, false)!=0) w->setHubName(hubname); w->handleSearchResult(u,f,s,sl,hubname); } } else { for(int i=0;i < hubTabs->count();i++) if( hubTabs->label(i) == hubname ) // found it { HubWdgt *w = (HubWdgt *)hubTabs->page(i); w->handleSearchResult(u,f,s,sl,hubname); } } } void MainWdgt::closeHubTab( ) { HubWdgt* hub = (HubWdgt*)hubTabs->currentPage(); if(!hub) return; if(hub->isConnected()) switch( QMessageBox::warning( this, "dc-qt", "Closing the hub tab will disconnect you from the hub and abort all transfers.\n", "Ok", "Cancel", 0, 0, 1 ) ) { case 0: // The user clicked the Ok again button or pressed Enter hubTabs->removePage( hub ); hub->disconnect(); delete hub; break; case 1: // The user clicked the Cancel button or pressed Escape break; } else { hubTabs->removePage( hub ); hub->disconnect(); delete hub; } } /// Connects the current hub void MainWdgt::connectHub() { HubWdgt* hub = (HubWdgt*)hubTabs->currentPage(); if(!hub) return; if(hub->connect()) { aConnect->setEnabled(false); aDisconnect->setEnabled(true); } } /// Disconnects the current hub void MainWdgt::disHub() { HubWdgt* hub = (HubWdgt*)hubTabs->currentPage(); if(!hub) return; hub->disconnect(); aConnect->setEnabled(true); aDisconnect->setEnabled(false); } /// Brings up the search dialog for the active hub void MainWdgt::searchHub() { HubWdgt* hub = (HubWdgt*)hubTabs->currentPage(); if(!hub) return; hub->openSearchDlg(); } void MainWdgt::closeEvent( QCloseEvent *e) { bool ask = false; int numclients; // save window position and size wnd_setting mainwndset(x(), y(), width(), height()); if (mainwndset.isValid()) { settings.set_setting("common","wndset_main", mainwndset.toString()); } // vertical split size list QValueList svli = mainbox->sizes(); intlist_setting sslist(svli); settings.set_setting("common","splitset_main", sslist.toString()); // save transfer widget layout transferWidget->save_layout(); if (preview_dlg!=NULL) delete preview_dlg; // Check if there are any connected hubs and save settings for(int i=0; i < hubTabs->count();i++) { HubWdgt *hub = (HubWdgt*)hubTabs->page(i); if( hub->isConnected() ) ask = true; if (i==0) hub->save_layout(); } settings.save_to_file(); if( ask ) { switch( QMessageBox::warning( this, "dc-qt", "Do you want to disconnect from all hubs before exiting?.\n", "Quit && &disconnect", "Just &Quit", "&Cancel", 0, 2 ) ) { case 0: for(int i=0; i < hubTabs->count();i++) { HubWdgt *hub = (HubWdgt*)hubTabs->page(i); hub->disconnect(); } usleep(500000); // We have closed all connections, see if we can kill the master as well. numclients = dc_hub::getNumClients(); #ifdef _DEBUG cout << "num clients running=" << numclients << "\n"; #endif if( numclients == 0) { dctc_hub::killMaster(); } //QMessageBox::warning(this,"Warning","Warning: dctc still running! You will have to kill them."); e->accept(); break; case 1: e->accept(); break; case 2: e->ignore(); } } else { // We didn't need to ask since all hubs where disconnected. // There could still be an unused master though. So kill it. numclients = dc_hub::getNumClients(); if( numclients == 0 ) dctc_hub::killMaster(); e->accept(); } } void MainWdgt::selectHub(QWidget *w) { HubWdgt *h = (HubWdgt *)w; if(h->isConnected()) { aConnect->setEnabled(false); aDisconnect->setEnabled(true); } else { aConnect->setEnabled(true); aDisconnect->setEnabled(false); } } void MainWdgt::displayHelp() { #define my_xstr(s) my_str(s) #define my_str(s) #s HelpWindow *hw = new HelpWindow("index.html", my_xstr(PREFIX) "/share/doc/dc-qt", 0,"scheisse"); debugWin->print(my_xstr(PREFIX) "/share/doc/dc-qt\n"); hw->show(); #undef my_xstr #undef my_str } // installtion registration void MainWdgt::register_installation() { if(!recvData.isNull() || current_op != NONE) { // wait a few secs and try again QTimer::singleShot(2000, this, SLOT(register_installation())); } else { QString ver(VERSION); ver.replace( QChar('.'), "" ); ver = ver.left(3); QString regver = settings.get_setting("registered_ver"); if (!ver.isEmpty() && regver != ver) { // not registered yet, need to ask int ret = QMessageBox::question(this, QString("Registering dc-qt %1").arg(VERSION), "Congratulations! It looks like you have installed a new version of dc-qt!" "\nYou can register this installation. By registering you help us know" "\nhow many people use different versions of dc-qt. No other information" "\nof any kind is collected." "\n\nPress 'Yes' to send notification now." "\n\nPress 'Later' if you don't want to register right now. This message" "\nwill be shown to you again next time you start dc-qt." "\n\nPress 'Never' if you don't ever want to register and don't want to be" "\nasked again." "\n\nAdditional options can be found in Preferences->Stats Reporting." ,"Yes", "Later", "Never", 0, 1); if (ret == 0) { // yes current_op = USER_REG; QString url = QString("cnt/register.php?dcqtv=") + ver; urlop->get(url); } else { if (ret == 2) { // never QString ver(VERSION); ver.replace( QChar('.'), "" ); ver = ver.left(3); settings.set_setting("common", "registered_ver", ver); settings.set_setting("common","register_never", "true"); settings.save_to_file(); } } } } } // session online registration void MainWdgt::register_session() { if(!recvData.isNull() || current_op!=NONE) { // wait a few secs and try again QTimer::singleShot(2000, this, SLOT(register_session())); } else { current_op = SESSION_REG; QString url("cnt/register.php?dcqtv=session"); urlop->get(url); } } /// Checks the newest version by obtaining a file from the dc-qt web page on sourceforge. void MainWdgt::checkVersion() { if(current_op != NONE) { // wait a few secs and try again QTimer::singleShot(2000, this, SLOT(checkVersion())); } else { current_op = VERSION_CHECK; checkDCTCVersion(); urlop->get("version.txt"); } } void MainWdgt::wwwxfer_incoming(const QByteArray &data, QNetworkOperation *op) { if(recvData.isNull()) recvData = data; else { uint oldSize = recvData.size(); recvData.resize(oldSize+data.size()); for(uint i=0;i < data.size();i++) recvData[i+oldSize] = data[i]; } } void MainWdgt::wwwxfer_finished(QNetworkOperation *op) { if(op->errorCode() == QNetworkProtocol::NoError) { switch (current_op) { case VERSION_CHECK: { QString text(recvData); QString version = text.section('\n',0,0); QString dctcversion = text.section('\n',1,1); QString changelog = text.section('\n',2); while(dctcVersion==QString::null) ; // ??? wtf is this? int curDctcV = 100*100*dctcVersion.section(".",0,0).toInt() + 100*dctcVersion.section(".",1,1).toInt() + dctcVersion.section(".",2,2).toInt(); int reqDctcV = 100*100*dctcversion.section(".",0,0).toInt() + 100*dctcversion.section(".",1,1).toInt() + dctcversion.section(".",2,2).toInt(); if(version==VERSION && curDctcV >= reqDctcV) QMessageBox::information(this,"Version checker", "Congratualtions, you have the latest version of dc-qt and the required version of DCTC.",QMessageBox::Yes); else QMessageBox::information(this,"Version checker", "Latest dc-qt version is " + version + "\nIt requires DCTC "+dctcversion+ "\nYour version of DCTC is "+dctcVersion+ "\nChangelog:\n"+changelog,QMessageBox::Ok); } break; case USER_REG: { QString ver(VERSION); ver.replace( QChar('.'), "" ); ver = ver.left(3); settings.set_setting("common", "registered_ver", ver); // strip html tags from data QString text(recvData); int i = text.find("",0,false); // skip header entirely text = text.right(text.length()-i); text.replace( "
", "\n", false ); // linebreaks text.replace( "

", "\n ", false ); // paragraphs text.replace( QRegExp("<[^<]*>"), "" ); // strip all other tags QMessageBox::information(this,"Registration successful", text, QMessageBox::Ok); } break; case SESSION_REG: { // strip html tags from data QString text(recvData); int i = text.find("",0,false); // skip header entirely text = text.right(text.length()-i); text.replace( QRegExp("<[^<]*>"), "" ); // strip all other tags text.replace( "\n", ""); // strip linebreaks showStatus(text); i = text.findRev('#'); setCaption( QString("dc-qt " VERSION " - session %1").arg(text.mid(i+1, text.length()-i-2)) ); } break; default: break; } } else { switch (current_op) { case VERSION_CHECK: QMessageBox::warning(this,"Version checker","Could not retrieve version. Check your internet connection.", "Dammit!"); break; case USER_REG: QMessageBox::warning(this,"Registration","Could not register online. Check your internet connection.", "Verdammt!"); break; case SESSION_REG: default: // say nothing break; } } recvData.resize(0); current_op = NONE; } static QProcess* dctcProc; bool MainWdgt::checkDCTCVersion() { dctcProc = new QProcess((QString)"dctc",this,"dctcversionproc"); connect(dctcProc,SIGNAL(processExited()),this,SLOT(dctcOutputReady())); dctcVersion = QString::null; return dctcProc->start(); } void MainWdgt::dctcOutputReady() { dctcVersion = dctcProc->readLineStdout().section(" ",-1,-1).mid(1,6); debugWin->print("DCTC version: " + dctcVersion); delete dctcProc; dctcProc = 0; } void MainWdgt::showStatus(const QString& str) { statusBar()->message(str,4000); } void MainWdgt::showProgress(const QString &msg,const QString &progress) { int p = (int)progress.toFloat(0); QString dir = msg.section(':',1,1); if(p==0 && !progressDlg) { //progressBar = new QProgressBar(100,this,"progressbar"); //progressBar->setProgress(0); //statusBar()->addWidget(progressBar,true); enableActions(false); progressDlg = new QProgressDialog("Building shared file database",QString::null,100,this); progressDlg->show(); statusBar()->message("Building shared file database",1000); } else if(p==100) { progressDlg->setProgress(100); delete progressDlg; progressDlg = 0; //statusBar()->removeWidget(progressBar); //delete progressBar; //progressBar = 0; enableActions(true); } else { //progressBar->setProgress(p); progressDlg->setLabelText("Building shared file database\n" + dir); progressDlg->setProgress(p); } } void MainWdgt::enableActions(bool yes) { aNewHub->setEnabled(yes); aCloseHub->setEnabled(yes); if(yes && !((HubWdgt*)hubTabs->currentPage())->isConnected()) aConnect->setEnabled(yes); aDisconnect->setEnabled(yes); aSearch->setEnabled(yes); aConfig->setEnabled(yes); aExit->setEnabled(yes); } void MainWdgt::reshare() { // Reshare the currently selected hub, if connected. HubWdgt* hub = (HubWdgt*)hubTabs->currentPage(); hub->reshare(); } int MainWdgt::getNumConnections() const { int ret = 0; for(int i=0; i < hubTabs->count();i++) if( ((HubWdgt*)hubTabs->page(i))->isConnected()) ret++; return ret; } const MainWdgt& MainWdgt::getInstance() { return *instance; } void MainWdgt::sendDCTCCommand() { QString cmd = QInputDialog::getText("Enter DCTC command","Enter DCTC command"); HubWdgt *w = (HubWdgt*)hubTabs->currentPage(); if(w) { w->sendDCTCCommand( cmd ); } } /* * * $Log: mainwdgt.cc,v $ * Revision 1.47 2004/08/23 08:49:05 estrato * docs path honors prefix, corrected fullscreen bug in preview * * Revision 1.46 2004/06/01 11:39:46 olof * small fixes * * Revision 1.45 2004/05/25 21:04:28 estrato * added userlist icon files * * Revision 1.44 2004/04/16 14:54:09 olof * fulfix * * Revision 1.43 2004/04/12 18:00:35 estrato * bleh in reg * * Revision 1.42 2004/04/07 23:15:47 estrato * register dialog fix * * Revision 1.41 2004/03/25 19:40:57 olof * Loads! * * Revision 1.40 2004/03/17 23:09:34 estrato * added profile icons * * Revision 1.39 2004/03/17 16:43:02 olof * connection profiles * * Revision 1.38 2004/03/13 22:49:04 estrato * stats reporting * * Revision 1.37 2004/03/13 08:31:54 estrato * online stats reporting added * * */