summaryrefslogtreecommitdiff
authorjosef <josef>2002-10-12 18:16:45 (UTC)
committer josef <josef>2002-10-12 18:16:45 (UTC)
commit82b04543125d6d856df180c437c8d9f95f41e888 (patch) (side-by-side diff)
treeb09807b9736d07d02dfa8a9dc79d385771be8c1a
parent9c983d273b055d847cf2d1fa4f5b6e082ce850c9 (diff)
downloadopie-82b04543125d6d856df180c437c8d9f95f41e888.zip
opie-82b04543125d6d856df180c437c8d9f95f41e888.tar.gz
opie-82b04543125d6d856df180c437c8d9f95f41e888.tar.bz2
- embed transferdialog into menu
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp16
-rw-r--r--noncore/apps/opie-console/mainwindow.h2
-rw-r--r--noncore/apps/opie-console/transferdialog.cpp44
-rw-r--r--noncore/apps/opie-console/transferdialog.h9
4 files changed, 65 insertions, 6 deletions
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index 0bd6a13..fbeaa74 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -1,217 +1,233 @@
#include <qaction.h>
#include <qmenubar.h>
#include <qlabel.h>
#include <qpopupmenu.h>
#include <qtoolbar.h>
#include "profileeditordialog.h"
#include "configdialog.h"
#include "default.h"
#include "metafactory.h"
#include "profile.h"
#include "profilemanager.h"
#include "mainwindow.h"
#include "tabwidget.h"
+#include "transferdialog.h"
MainWindow::MainWindow() {
m_factory = new MetaFactory();
Default def(m_factory);
m_sessions.setAutoDelete( TRUE );
m_curSession = 0;
m_manager = new ProfileManager( m_factory );
m_manager->load();
initUI();
populateProfiles();
}
void MainWindow::initUI() {
setToolBarsMovable( FALSE );
m_tool = new QToolBar( this );
m_tool->setHorizontalStretchable( TRUE );
m_bar = new QMenuBar( m_tool );
m_console = new QPopupMenu( this );
m_sessionsPop= new QPopupMenu( this );
m_settings = new QPopupMenu( this );
/*
* new Action for new sessions
*/
QAction* a = new QAction();
a->setText( tr("New Connection") );
a->addTo( m_console );
connect(a, SIGNAL(activated() ),
this, SLOT(slotNew() ) );
/*
* connect action
*/
m_connect = new QAction();
m_connect->setText( tr("Connect") );
m_connect->addTo( m_console );
connect(m_connect, SIGNAL(activated() ),
this, SLOT(slotConnect() ) );
/*
* disconnect action
*/
m_disconnect = new QAction();
m_disconnect->setText( tr("Disconnect") );
m_disconnect->addTo( m_console );
connect(m_disconnect, SIGNAL(activated() ),
this, SLOT(slotDisconnect() ) );
+ m_transfer = new QAction();
+ m_transfer->setText( tr("Transfer file...") );
+ m_transfer->addTo( m_console );
+ connect(m_transfer, SIGNAL(activated() ),
+ this, SLOT(slotTransfer() ) );
+
/*
* terminate action
*/
m_terminate = new QAction();
m_terminate->setText( tr("Terminate") );
m_terminate->addTo( m_console );
connect(m_terminate, SIGNAL(activated() ),
this, SLOT(slotTerminate() ) );
a = new QAction();
a->setText( tr("Close Window") );
a->addTo( m_console );
connect(a, SIGNAL(activated() ),
this, SLOT(slotClose() ) );
/*
* the settings action
*/
m_setProfiles = new QAction();
m_setProfiles->setText( tr("Configure Profiles") );
m_setProfiles->addTo( m_settings );
connect( m_setProfiles, SIGNAL(activated() ),
this, SLOT(slotConfigure() ) );
/* insert the submenu */
m_console->insertItem(tr("New from Profile"), m_sessionsPop,
-1, 0);
/* insert the connection menu */
m_bar->insertItem( tr("Connection"), m_console );
/* the settings menu */
m_bar->insertItem( tr("Settings"), m_settings );
/*
* connect to the menu activation
*/
connect( m_sessionsPop, SIGNAL(activated( int ) ),
this, SLOT(slotProfile( int ) ) );
m_consoleWindow = new TabWidget( this, "blah");
setCentralWidget( m_consoleWindow );
}
ProfileManager* MainWindow::manager() {
return m_manager;
}
TabWidget* MainWindow::tabWidget() {
return m_consoleWindow;
}
void MainWindow::populateProfiles() {
m_sessionsPop->clear();
Profile::ValueList list = manager()->all();
for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) {
m_sessionsPop->insertItem( (*it).name() );
}
}
MainWindow::~MainWindow() {
delete m_factory;
manager()->save();
}
MetaFactory* MainWindow::factory() {
return m_factory;
}
Session* MainWindow::currentSession() {
return m_curSession;
}
QList<Session> MainWindow::sessions() {
return m_sessions;
}
void MainWindow::slotNew() {
qWarning("New Connection");
ProfileEditorDialog dlg(factory() );
int ret = dlg.exec();
if ( ret == QDialog::Accepted ) {
create( dlg.profile() );
}
}
void MainWindow::slotConnect() {
if ( currentSession() )
currentSession()->layer()->open();
}
void MainWindow::slotDisconnect() {
if ( currentSession() )
currentSession()->layer()->close();
}
void MainWindow::slotTerminate() {
if ( currentSession() )
currentSession()->layer()->close();
slotClose();
/* FIXME move to the next session */
}
void MainWindow::slotConfigure() {
qWarning("configure");
ConfigDialog conf( manager()->all(), factory() );
conf.showMaximized();
int ret = conf.exec();
if ( QDialog::Accepted == ret ) {
qWarning("conf %d", conf.list().count() );
manager()->setProfiles( conf.list() );
populateProfiles();
}
}
/*
* we will remove
* this window from the tabwidget
* remove it from the list
* delete it
* and set the currentSession()
*/
void MainWindow::slotClose() {
qWarning("close");
if (!currentSession() )
return;
tabWidget()->remove( currentSession() );
/*it's autodelete */
m_sessions.remove( m_curSession );
m_curSession = m_sessions.first();
tabWidget()->setCurrent( m_curSession );
}
/*
* We will get the name
* Then the profile
* and then we will make a profile
*/
void MainWindow::slotProfile( int id) {
Profile prof = manager()->profile( m_sessionsPop->text( id) );
create( prof );
}
void MainWindow::create( const Profile& prof ) {
Session *ses = manager()->fromProfile( prof, tabWidget() );
m_sessions.append( ses );
tabWidget()->add( ses );
m_curSession = ses;
+
}
+
+void MainWindow::slotTransfer()
+{
+ TransferDialog dlg(this);
+ dlg.showMaximized();
+ dlg.exec();
+}
+
diff --git a/noncore/apps/opie-console/mainwindow.h b/noncore/apps/opie-console/mainwindow.h
index 7ef9c26..c8b0b65 100644
--- a/noncore/apps/opie-console/mainwindow.h
+++ b/noncore/apps/opie-console/mainwindow.h
@@ -1,93 +1,95 @@
#ifndef OPIE_MAIN_WINDOW_H
#define OPIE_MAIN_WINDOW_H
#include <qmainwindow.h>
#include <qlist.h>
#include "session.h"
/**
* this is the MainWindow of the new opie console
* it's also the dispatcher between the different
* actions supported by the gui
*/
class QToolBar;
class QMenuBar;
class QAction;
class MetaFactory;
class TabWidget;
class ProfileManager;
class Profile;
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow();
~MainWindow();
/**
* our factory to generate IOLayer and so on
*
*/
MetaFactory* factory();
/**
* A session contains a QWidget*,
* an IOLayer* and some infos for us
*/
Session* currentSession();
/**
* the session list
*/
QList<Session> sessions();
/**
*
*/
ProfileManager* manager();
TabWidget* tabWidget();
private slots:
void slotNew();
void slotConnect();
void slotDisconnect();
void slotTerminate();
void slotConfigure();
void slotClose();
void slotProfile(int);
+ void slotTransfer();
private:
void initUI();
void populateProfiles();
void create( const Profile& );
/**
* the current session
*/
Session* m_curSession;
/**
* the session list
*/
QList<Session> m_sessions;
/**
* the metafactory
*/
MetaFactory* m_factory;
ProfileManager* m_manager;
TabWidget* m_consoleWindow;
QToolBar* m_tool;
QMenuBar* m_bar;
QPopupMenu* m_console;
QPopupMenu* m_settings;
QPopupMenu* m_sessionsPop;
QAction* m_connect;
QAction* m_disconnect;
QAction* m_terminate;
+ QAction* m_transfer;
QAction* m_setProfiles;
};
#endif
diff --git a/noncore/apps/opie-console/transferdialog.cpp b/noncore/apps/opie-console/transferdialog.cpp
index 08fb32b..45522a8 100644
--- a/noncore/apps/opie-console/transferdialog.cpp
+++ b/noncore/apps/opie-console/transferdialog.cpp
@@ -1,92 +1,128 @@
#include "transferdialog.h"
+#include "filetransfer.h"
+#include "io_serial.h"
+
#include "qlayout.h"
#include "qcombobox.h"
#include "qlabel.h"
#include "qlineedit.h"
#include "qpushbutton.h"
#include "qmessagebox.h"
#include "qprogressbar.h"
#include "opie/ofiledialog.h"
TransferDialog::TransferDialog(QWidget *parent, const char *name)
-: QWidget(parent, name)
+: QDialog(/*parent, name*/NULL, NULL, true)
{
QVBoxLayout *vbox;
QHBoxLayout *hbox, *hbox2;
QLabel *file, *mode, *progress, *status;
- QPushButton *selector, *ok, *cancel;
+ QPushButton *selector;
+
+ transfer = NULL;
file = new QLabel(QObject::tr("Send file"), this);
mode = new QLabel(QObject::tr("Transfer mode"), this);
progress = new QLabel(QObject::tr("Progress"), this);
status = new QLabel(QObject::tr("Status"), this);
statusbar = new QLabel(QObject::tr("ready"), this);
statusbar->setFrameStyle(QFrame::Panel | QFrame::Sunken);
protocol = new QComboBox(this);
protocol->insertItem("XModem");
protocol->insertItem("YModem");
protocol->insertItem("ZModem");
filename = new QLineEdit(this);
progressbar = new QProgressBar(this);
progressbar->setProgress(0);
selector = new QPushButton("...", this);
- ok = new QPushButton(QObject::tr("OK"), this);
+ ok = new QPushButton(QObject::tr("Start transfer"), this);
cancel = new QPushButton(QObject::tr("Cancel"), this);
vbox = new QVBoxLayout(this, 2);
vbox->add(file);
hbox = new QHBoxLayout(vbox, 0);
hbox->add(filename);
hbox->add(selector);
vbox->add(mode);
vbox->add(protocol);
vbox->add(progress);
vbox->add(progressbar);
vbox->add(status);
vbox->add(statusbar);
vbox->addStretch(1);
hbox2 = new QHBoxLayout(vbox, 2);
hbox2->add(ok);
hbox2->add(cancel);
setCaption(QObject::tr("File transfer"));
show();
connect(selector, SIGNAL(clicked()), SLOT(slotFilename()));
connect(ok, SIGNAL(clicked()), SLOT(slotTransfer()));
- connect(cancel, SIGNAL(clicked()), SLOT(close()));
+ connect(cancel, SIGNAL(clicked()), SLOT(slotCancel()));
}
TransferDialog::~TransferDialog()
{
}
void TransferDialog::slotFilename()
{
QString f;
f = OFileDialog::getOpenFileName(0);
if(!f.isNull()) filename->setText(f);
}
void TransferDialog::slotTransfer()
{
if(filename->text().isEmpty())
{
QMessageBox::information(this,
QObject::tr("Attention"),
QObject::tr("No file has been specified."));
return;
}
+ ok->setEnabled(false);
+
statusbar->setText(QObject::tr("Sending..."));
progressbar->setProgress(1);
+
+ FileTransfer::Type transfermode = FileTransfer::SX;
+ if(protocol->currentText() == "YModem") transfermode == FileTransfer::SY;
+ if(protocol->currentText() == "ZModem") transfermode == FileTransfer::SZ;
+
+ // dummy profile
+ Profile profile("Dummy", "serial", "vt102", Profile::White, Profile::Black, Profile::VT102);
+
+ transfer = new FileTransfer(transfermode, new IOSerial(profile));
+ transfer->sendFile(filename->text());
+}
+
+void TransferDialog::slotCancel()
+{
+ ok->setEnabled(true);
+
+ if(transfer)
+ {
+ transfer->cancel();
+ delete transfer;
+ transfer = NULL;
+ QMessageBox::information(this,
+ QObject::tr("Cancelled"),
+ QObject::tr("The file transfer has been cancelled."));
+ }
+ else
+ {
+ close();
+ }
}
diff --git a/noncore/apps/opie-console/transferdialog.h b/noncore/apps/opie-console/transferdialog.h
index 4fe17dd..62ae14d 100644
--- a/noncore/apps/opie-console/transferdialog.h
+++ b/noncore/apps/opie-console/transferdialog.h
@@ -1,30 +1,35 @@
#ifndef TRANSFER_DIALOG_H
#define TRANSFER_DIALOG_H
-#include "qwidget.h"
+#include "qdialog.h"
class QLineEdit;
class QComboBox;
class QProgressBar;
class QLabel;
+class QPushButton;
+class FileTransfer;
-class TransferDialog : public QWidget
+class TransferDialog : public QDialog
{
Q_OBJECT
public:
TransferDialog(QWidget *parent = NULL, const char *name = NULL);
~TransferDialog();
public slots:
void slotFilename();
void slotTransfer();
+ void slotCancel();
private:
QLineEdit *filename;
QComboBox *protocol;
QProgressBar *progressbar;
QLabel *statusbar;
+ QPushButton *ok, *cancel;
+ FileTransfer *transfer;
};
#endif