summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/filereceive.cpp4
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp4
-rw-r--r--noncore/apps/opie-console/logger.cpp4
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp3
-rw-r--r--noncore/apps/opie-console/script.cpp6
-rw-r--r--noncore/apps/opie-gutenbrowser/gutenbrowser.cpp26
-rw-r--r--noncore/apps/opie-gutenbrowser/helpwindow.cpp64
-rw-r--r--noncore/graphics/opie-eye/slave/bmp_slave.cpp4
-rw-r--r--noncore/net/ftplib/ftplib.c8
-rw-r--r--noncore/todayplugins/stockticker/stockticker/helpwindow.cpp42
-rw-r--r--noncore/todayplugins/weather/weatherpluginwidget.cpp5
-rw-r--r--noncore/tools/opie-sh/inputdialog.cpp20
12 files changed, 101 insertions, 89 deletions
diff --git a/noncore/apps/opie-console/filereceive.cpp b/noncore/apps/opie-console/filereceive.cpp
index 452be60..41e6888 100644
--- a/noncore/apps/opie-console/filereceive.cpp
+++ b/noncore/apps/opie-console/filereceive.cpp
@@ -1,162 +1,164 @@
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
+#include <opie2/odebug.h>
#include <qsocketnotifier.h>
#include "io_layer.h"
#include "procctl.h"
#include "filereceive.h"
FileReceive::FileReceive( Type t, IOLayer* lay, const QString& dir )
: ReceiveLayer(lay, dir ), m_type( t )
{
m_fd = -1;
m_not = 0l;
m_proc = 0l;
}
FileReceive::~FileReceive() {
}
void FileReceive::receive() {
receive( currentDir() );
}
void FileReceive::receive( const QString& dir ) {
m_prog = -1;
m_fd = layer()->rawIO();
m_curDir = dir;
if (pipe( m_comm ) < 0 )
m_comm[0] = m_comm[1] = 0;
if (pipe( m_info ) < 0 )
m_info[0] = m_info[1] = 0;
m_pid = fork();
switch( m_pid ) {
case -1:
//emit error
slotExec();
break;
/* child */
case 0: {
setupChild();
char* typus = NULL;
switch(m_type ) {
case SZ:
break;
case SX:
typus = "-X";
break;
case SY:
typus = "--ymodem";
break;
}
/* we should never return from here */
if( m_type == SX )
// FIXME: file name should be configurable - currently we ensure it
// doesn't get overwritten by -E (--rename)
execlp("rz", "rz", typus, "--overwrite", QObject::tr("SynchronizedFile").latin1(), NULL );
else
execlp("rz", "rz", typus, "--overwrite", NULL );
char resultByte = 1;
if (m_info[1] )
::write(m_info[1], &resultByte, 1 );
_exit( -1 );
break;
}
default: {
if ( m_info[1] )
close( m_info[1] );
if ( m_info[0] ) for (;;) {
char resultByte; int len;
len = read(m_info[0], &resultByte, 1 );
/* len == 1 start up failed */
if ( len == 1 ) {
emit error( StartError, tr("Could not start") );
return;
}
if ( len == -1 )
if ( (errno == ECHILD ) || (errno == EINTR ) )
continue;
// len == 0 or something like this
break;
}
if ( m_info[0] )
close( m_info[0] );
m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read );
connect(m_not, SIGNAL(activated(int) ),
this, SLOT(slotRead() ) );
if ( pipe(m_term) < 0 )
m_term[0] = m_term[1] = 0;
ProcCtl::self()->add(m_pid, m_term[1] );
m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read );
connect(m_proc, SIGNAL(activated(int) ),
this, SLOT(slotExec() ) );
}
break;
}
}
void FileReceive::cancel() {
::kill(m_pid, 9 );
}
void FileReceive::setupChild() {
changeDir( currentDir() );
/*
* we do not want to read from our
* information channel
*/
if (m_info[0] )
close(m_info[0] );
/*
* FD_CLOEXEC will close the
* fd on successful exec
*/
if (m_info[1] )
fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
if (m_comm[0] )
close( m_comm[0] );
/*
* now set the communication
* m_fd STDIN_FILENO
* STDOUT_FILENO
* STDERR_FILENO
*/
dup2( m_fd, STDIN_FILENO );
dup2( m_fd, STDOUT_FILENO );
dup2( m_comm[1], STDERR_FILENO );
}
void FileReceive::slotRead() {
QByteArray ar(4096);
int len = read(m_comm[0], ar.data(), 4096 );
for (int i = 0; i < len; i++ ) {
// printf("%c", ar[i] );
}
ar.resize( len );
QString str( ar );
}
void FileReceive::slotExec() {
char buf[2];
- ::read(m_term[0], buf, 1 );
+ if (::read(m_term[0], buf, 1 ) == -1)
+ owarn << "read of m_term[0] failed" << oendl;
delete m_proc;
delete m_not;
m_not = m_proc = 0l;
close( m_term[0] );
close( m_term[1] );
close( m_comm[0] );
close( m_comm[1] );
layer()->closeRawIO(m_fd);
emit received(QString::null);
}
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
index 7eebc65..6e2d2d5 100644
--- a/noncore/apps/opie-console/filetransfer.cpp
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -1,102 +1,103 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
+#include <opie2/odebug.h>
#include <qsocketnotifier.h>
#include "procctl.h"
#include "filetransfer.h"
FileTransfer::FileTransfer( Type t, IOLayer* lay )
: FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) {
signal(SIGPIPE, SIG_IGN );
m_pid = 0;
m_not = 0l;
m_proc = 0l;
}
FileTransfer::~FileTransfer() {
}
/**
* now we will send the file.
*
* we request an fd. The IOLayer should be closed
* then we will setup a pipe for progress communication
* then we will dup2 the m_fd in the forked process
* to do direct IO from and to the fd
*/
void FileTransfer::sendFile( const QString& file ) {
m_prog =-1;
m_fd = layer()->rawIO();
//
// m_fd = ::open("/dev/ttyS0", O_RDWR);
m_file = file;
if ( pipe( m_comm ) < 0 )
m_comm[0] = m_comm[1] = 0;
if ( pipe( m_info ) < 0 )
m_info[0] = m_info[1] = 0;
m_pid = fork();
switch( m_pid ) {
case -1:
emit error( StartError, tr("Was not able to fork") );
slotExec();
break;
case 0:{
setupChild();
/* exec */
char* verbose = "-vv";
char* binray = "-b";
char* typus;
switch(m_type ) {
default:
case SZ:
typus = "";
break;
case SX:
typus = "-X";
break;
case SY:
typus = "--ymodem";
break;
}
/* we should never return from here */
execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL );
/* communication for error!*/
char resultByte =1;
if (m_info[1] )
write(m_info[1], &resultByte, 1 );
_exit( -1 );
break;
}
default:{
if ( m_info[1] )
close( m_info[1] );
if ( m_info[0] ) for (;;) {
char resultByte; int len;
len = read(m_info[0], &resultByte, 1 );
/* len == 1 start up failed */
if ( len == 1 ) {
emit error( StartError, tr("Could not start") );
return;
}
if ( len == -1 )
if ( (errno == ECHILD ) || (errno == EINTR ) )
continue;
// len == 0 or something like this
break;
}
if ( m_info[0] )
close( m_info[0] );
@@ -141,108 +142,109 @@ void FileTransfer::setupChild() {
* fd on successful exec
*/
if (m_info[1] )
fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
if (m_comm[0] )
close( m_comm[0] );
/*
* now set the communication
* m_fd STDIN_FILENO
* STDOUT_FILENO
* STDERR_FILENO
*/
dup2( m_fd, STDIN_FILENO );
dup2( m_fd, STDOUT_FILENO );
dup2( m_comm[1], STDERR_FILENO );
}
/*
* read from the stderr of the child
* process
*/
void FileTransfer::slotRead() {
QByteArray ar(4096);
int len = read(m_comm[0], ar.data(), 4096 );
for (int i = 0; i < len; i++ ) {
// printf("%c", ar[i] );
}
ar.resize( len );
QString str( ar );
QStringList lis = QStringList::split(' ', str );
/*
* Transfer finished.. either complete or incomplete
*/
if ( lis[0].simplifyWhiteSpace() == "Transfer" ) {
return;
}
/*
* do progress reading
*/
slotProgress( lis );
}
/*
* find the progress
*/
void FileTransfer::slotProgress( const QStringList& list ) {
if ( m_type != SZ )
return;
bool complete = true;
int min, sec;
int bps;
unsigned long sent, total;
min = sec = bps = -1;
sent = total = 0;
// Data looks like this
// 0 1 2 3 4 5
// Bytes Sent 65536/11534336 BPS:7784 ETA 24:33
QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() );
sent = progi[0].toULong(&complete );
if (!complete ) return;
total = progi[1].toULong(&complete );
if (!complete || total == 0) {
return;
}
double pro = (double)sent/total;
int prog = pro * 100;
// speed
progi = QStringList::split(':', list[3].simplifyWhiteSpace() );
bps = progi[1].toInt();
// time
progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
min = progi[0].toInt();
sec = progi[1].toInt();
if ( prog > m_prog ) {
m_prog = prog;
emit progress(m_file, m_prog, bps, -1, min , sec );
}
}
void FileTransfer::cancel() {
if(m_pid > 0) ::kill(m_pid,9 );
}
void FileTransfer::slotExec() {
char buf[2];
- ::read(m_term[0], buf, 1 );
+ if (::read(m_term[0], buf, 1 ) == -1)
+ owarn << "read of m_term[0] failed" << oendl;
delete m_proc;
delete m_not;
m_proc = m_not = 0l;
close( m_term[0] );
close( m_term[1] );
close( m_comm[0] );
close( m_comm[1] );
layer()->closeRawIO( m_fd );
emit sent();
m_pid = 0;
}
diff --git a/noncore/apps/opie-console/logger.cpp b/noncore/apps/opie-console/logger.cpp
index 6620faf..0fdeca0 100644
--- a/noncore/apps/opie-console/logger.cpp
+++ b/noncore/apps/opie-console/logger.cpp
@@ -1,20 +1,22 @@
#include <qfile.h>
#include <qtextstream.h>
+#include <opie2/odebug.h>
#include "logger.h"
Logger::Logger() {}
Logger::Logger(const QString fileName) {
m_file.setName(fileName);
- m_file.open(IO_ReadWrite);
+ if ( !m_file.open(IO_ReadWrite) )
+ owarn << "failed to open " << m_file.name() << oendl;
}
Logger::~Logger() {
m_file.close();
}
void Logger::append(QByteArray ar) {
m_file.writeBlock(ar);
}
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index 18c0434..aba7244 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -731,104 +731,105 @@ void MainWindow::slotScrollbarSelected(int index)
}
m_scrollbar->setItemChecked(sm_none, index == sm_none);
m_scrollbar->setItemChecked(sm_left, index == sm_left);
m_scrollbar->setItemChecked(sm_right, index == sm_right);
}
void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) {
if ( m_curSession ) {
QEvent::Type state;
if (pressed) state = QEvent::KeyPress;
else state = QEvent::KeyRelease;
QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode)));
// is this the best way to do this? cant figure out any other way to work
QApplication::sendEvent((QObject *)m_curSession->widget(), &ke);
ke.ignore();
}
}
void MainWindow::slotCopy() {
if (!currentSession() ) return;
currentSession()->emulationHandler()->copy();
}
void MainWindow::slotPaste() {
if (!currentSession() ) return;
currentSession()->emulationHandler()->paste();
}
/*
* Save the session
*/
void MainWindow::slotSaveSession() {
if (!currentSession() ) {
QMessageBox::information(this, tr("Save Connection"),
tr("<qt>There is no Connection.</qt>"), 1 );
return;
}
manager()->add( currentSession()->profile() );
manager()->save();
populateProfiles();
}
void MainWindow::slotSaveLog() {
if( currentSession()->emulationHandler()->isLogging() ) {
DocLnk nf;
QString m_logName = currentSession()->emulationHandler()->logFileName();
QFileInfo info(m_logName);
nf.setType("text/plain");
nf.setFile(m_logName);
nf.setName(info.fileName());
nf.writeLink();
m_recordLog->setText( tr("Start log") );
m_recordingLog = false;
currentSession()->emulationHandler()->clearLog();
} else {
QMap<QString, QStringList> map;
QStringList text;
text << "text/plain";
map.insert(tr("Log"), text );
Opie::Core::OConfig cfg("opie-console");
cfg.setGroup("defaults");
QString startDir = cfg.readEntry("defaultlogdir", QPEApplication::documentDir() );
QString m_logName = OFileDialog::getSaveFileName(2, startDir, QString::null, map, 0, startDir);
if (m_logName.isEmpty() ) return;
m_recordLog->setText( tr("Stop log") );
m_recordingLog = true;
currentSession()->emulationHandler()->startLogging(m_logName);
}
}
void MainWindow::slotSaveHistory() {
QMap<QString, QStringList> map;
QStringList text;
text << "text/plain";
map.insert(tr("History"), text );
QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
if (filename.isEmpty() ) return;
QFileInfo info(filename);
DocLnk nf;
nf.setType("text/plain");
nf.setFile(filename);
nf.setName(info.fileName());
QFile file(filename);
- file.open(IO_WriteOnly );
+ if ( !file.open(IO_WriteOnly ) ) return;
+
QTextStream str(&file );
if ( currentSession() )
currentSession()->emulationHandler()->emulation()->streamHistory(&str);
file.close();
nf.writeLink();
}
diff --git a/noncore/apps/opie-console/script.cpp b/noncore/apps/opie-console/script.cpp
index faea412..8d35776 100644
--- a/noncore/apps/opie-console/script.cpp
+++ b/noncore/apps/opie-console/script.cpp
@@ -1,29 +1,31 @@
#include <qfile.h>
#include "script.h"
Script::Script() {
}
Script::Script(const QString fileName) {
QFile file(fileName);
- file.open(IO_ReadOnly );
+ if ( !file.open(IO_ReadOnly ) )
+ return;
m_script = file.readAll();
}
void Script::saveTo(const QString fileName) const {
QFile file(fileName);
- file.open(IO_WriteOnly);
+ if ( !file.open(IO_WriteOnly) )
+ return;
file.writeBlock(m_script);
file.close();
}
void Script::append(const QByteArray &data) {
int size = m_script.size();
m_script.resize(size + data.size());
memcpy(m_script.data() + size, data.data(), data.size());
}
QByteArray Script::script() const {
return m_script;
}
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
index 733db17..8b02f9f 100644
--- a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
+++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
@@ -752,208 +752,202 @@ void Gutenbrowser::Bookmark( int itemId) {
}
odebug << "bookmark loaded" << oendl;
setCaption(title);
}
bool Gutenbrowser::load( const char *fileName) {
// QCopEnvelope ( "QPE/System", "busy()" );
odebug << "Title is already set as "+title << oendl;
odebug << "sizeHint " << sizeHint().height() << " pageSize " << Lview->PageSize() << "" << oendl;
// pointSize = Lview->fontInfo().pointSize();
// odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl;
if( Lview->PageSize() < 4) {
// Lview->setMaximumHeight( sizeHint().height() );
Lview->setMinimumHeight( sizeHint().height() );
pointSize = Lview->fontInfo().pointSize();
odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl;
if(pointSize < 15)
Lview->setFixedVisibleLines(19);
else
Lview->setFixedVisibleLines( ( (sizeHint().height() / pointSize ) * 2) -2);
}
Config cfg("Gutenbrowser");
cfg.setGroup("General");
cfg.writeEntry("Current",fileName);
cfg.write();
currentLine=0;
file_name=fileName;
QString o_file = fileName;
// if (i_pageNum < 1) {
i_pageNum = 1;
// }
odebug << "ready to open "+o_file << oendl;
if(f.isOpen()) f.close();
f.setName( o_file);
if ( !f.open( IO_ReadOnly)) {
QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n" +o_file)) );
return false;
}
currentFilePos = 0;
pageStopArray.resize(3);
pageStopArray[0] = currentFilePos;
fileHandle = f.handle();
QString insertString;
QTextStream t(&f);
QString s;
for(int fd=0; fd < Lview->PageSize() ;fd++) {
s=t.readLine();
// insertString+=s;
if(useWrap)
s.replace(QRegExp("\n"),"");
// s.replace(QRegExp("\r"),"");
Lview->insertLine( s,-1);
currentLine++;
}
// int length = Lview->length();
currentFilePos = f.at();
pageStopArray[1] = currentFilePos;
odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum
<< ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum]
<< ", pageSize " << Lview->PageSize() << oendl;
Lview->setMaxLines(Lview->PageSize()*2);
// odebug << "Gulped " << currentLine << "" << oendl;
setCaption(title);
Lview->setAutoUpdate( TRUE);
// Lview->setCursorPosition(0,0,FALSE);
// pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1;
//odebug << "number of pages " << pages << "" << oendl;
loadCheck = true;
enableButtons(true);
if( donateMenu->count() == 3) {
donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() ));
}
Lview->setFocus();
// QCopEnvelope("QPE/System", "notBusy()" );
return true;
} // end load
void Gutenbrowser::Search() {
-
- // if( searchDlg->isHidden())
- {
- odebug << "Starting search dialog" << oendl;
- searchDlg = new SearchDialog( this, "Etext Search", true);
- searchDlg->setCaption( tr( "Etext Search" ));
- // searchDlg->setLabel( "- searches etext");
- connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot()));
- connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot()));
-
- QString resultString;
- QString string = searchDlg->searchString;
- Lview->deselect();
- searchDlg->show();
- searchDlg->result();
- }
+ odebug << "Starting search dialog" << oendl;
+ searchDlg = new SearchDialog( this, "Etext Search", true);
+ searchDlg->setCaption( tr( "Etext Search" ));
+ connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot()));
+ connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot()));
+
+ QString resultString;
+ QString string = searchDlg->searchString;
+ Lview->deselect();
+ searchDlg->show();
}
void Gutenbrowser::search_slot( ) {
int line, col;
if (!searchDlg /*&& !loadCheck */)
return;
Lview->getCursorPosition(&line,&col);
QString to_find_string=searchDlg->get_text();
// searchDlg->get_direction();// is true if searching backward
if ( last_search != 0 && searchDlg->get_direction() ){
col = col - pattern.length() - 1 ;
}
again:
int result = doSearch( to_find_string , /* searchDlg->case_sensitive()*/ TRUE, searchDlg->forward_search(), line, col);
if(result == 0){
if(!searchDlg->get_direction()){ // forward search
int query = QMessageBox::information( searchDlg, "Find",
"End of document reached.\nContinue from the beginning?",
"Yes", "No", "", 0,1);
if (query == 0){
line = 0;
col = 0;
goto again;
}
} else { //backward search
int query = QMessageBox::information( searchDlg, "Find",
"End of document reached.\nContinue from the beginning?",
"Yes", "No", "", 0,1);
if (query == 0){
QString string = Lview->textLine( Lview->numLines() - 1 );
line = Lview->numLines() - 1;
lineCheck = line;
col = string.length();
last_search = -1; //BACKWARD;
goto again;
}
}
} else {
//// emit CursorPositionChanged(); textLine
}
}
int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) {
int i, length;
int pos = -1;
if(forward) {
QString string;
for(i = line; i < Lview->numLines(); i++) {
string = Lview->textLine(i);
pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
if( pos != -1) {
int top = Lview->Top();
length = s_pattern.length();
if( i > Lview->lastRow() ) {
// Lview->setCursorPosition(i,pos,FALSE);
for(int l = 0 ; l < length; l++) {
Lview->cursorRight(TRUE);
}
// Lview->setCursorPosition( i , pos + length, TRUE );
int newTop = Lview->Top();
if(Lview->lastRow() > i)
Lview->ScrollUp( newTop - top);
// AdjustStatus();
} else {
// Lview->setCursorPosition(i,pos,FALSE);
for(int l = 0 ; l < length; l++) {
Lview->cursorRight(TRUE);
}
// Lview->setCursorPosition( i , pos + length, TRUE );
// AdjustStatus();
}
pattern = s_pattern;
last_search = 1; //FORWARD;
return 1;
}
}
} else { //////////////// searching backwards
QString string;
for( i = line; i >= 0; i--) {
string = Lview->textLine(i);
int line_length = string.length();
pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
if (pos != -1) {
// int top = Lview->Top();
length = s_pattern.length();
if( i < Lview->Top() ) {
Lview->ScrollDown( Lview->PageSize() );
Lview->MultiLine_Ex::pageUp( FALSE );
if( ! (line == i && pos > col ) ) {
// Lview->setCursorPosition( i ,pos ,FALSE );
for(int l = 0 ; l < length; l++) {
Lview->cursorRight(TRUE);
diff --git a/noncore/apps/opie-gutenbrowser/helpwindow.cpp b/noncore/apps/opie-gutenbrowser/helpwindow.cpp
index 4bdac02..f444a2e 100644
--- a/noncore/apps/opie-gutenbrowser/helpwindow.cpp
+++ b/noncore/apps/opie-gutenbrowser/helpwindow.cpp
@@ -100,234 +100,232 @@ HelpWindow::HelpWindow( const QString& home_, const QString&, QWidget* parent, c
QStringList::Iterator it2 = bookmarks.begin();
for ( ; it2 != bookmarks.end(); ++it2 )
mBookmarks[ bookm->insertItem( *it2 ) ] = *it2;
connect( bookm, SIGNAL( activated( int ) ),
this, SLOT( bookmChosen( int ) ) );
menuBar()->insertItem( tr("&File"), file );
menuBar()->insertItem( tr("&Go"), go );
menuBar()->insertItem( tr( "History" ), hist );
menuBar()->insertItem( tr( "Bookmarks" ), bookm );
// menuBar()->insertSeparator();
// menuBar()->insertItem( tr("&Help"), help );
menuBar()->setItemEnabled( forwardId, FALSE);
menuBar()->setItemEnabled( backwardId, FALSE);
connect( browser, SIGNAL( backwardAvailable( bool ) ), this, SLOT( setBackwardAvailable( bool ) ) );
connect( browser, SIGNAL( forwardAvailable( bool ) ), this, SLOT( setForwardAvailable( bool ) ) );
QToolBar* toolbar = new QToolBar( this );
addToolBar( toolbar, "Toolbar");
QToolButton* button;
button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar );
connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
button->setEnabled( FALSE );
button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar );
connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
button->setEnabled( FALSE );
button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar );
toolbar->addSeparator();
pathCombo = new QComboBox( TRUE, toolbar );
connect( pathCombo, SIGNAL( activated( const QString & ) ), this, SLOT( pathSelected( const QString & ) ) );
toolbar->setStretchableWidget( pathCombo );
// pathCombo->setMaximumWidth(190);
// setRightJustification( TRUE );
// setDockEnabled( Left, FALSE );
// setDockEnabled( Right, FALSE );
pathCombo->insertItem( home_ );
browser->setFocus();
}
void HelpWindow::setBackwardAvailable( bool b)
{
menuBar()->setItemEnabled( backwardId, b);
}
void HelpWindow::setForwardAvailable( bool b)
{
menuBar()->setItemEnabled( forwardId, b);
}
void HelpWindow::textChanged()
{
if ( browser->documentTitle().isNull() ) {
setCaption( "Gutenbrowser - Helpviewer - " + browser->context() );
selectedURL = browser->context();
}
else {
setCaption( "Gutenbrowser - Helpviewer - " + browser->documentTitle() ) ;
selectedURL = browser->documentTitle();
}
if ( !selectedURL.isEmpty() && pathCombo ) {
bool exists = FALSE;
int i;
for ( i = 0; i < pathCombo->count(); ++i ) {
if ( pathCombo->text( i ) == selectedURL ) {
exists = TRUE;
break;
}
}
if ( !exists ) {
pathCombo->insertItem( selectedURL, 0 );
pathCombo->setCurrentItem( 0 );
mHistory[ hist->insertItem( selectedURL ) ] = selectedURL;
} else
pathCombo->setCurrentItem( i );
selectedURL = QString::null;
}
}
HelpWindow::~HelpWindow()
{
history.clear();
QMap<int, QString>::Iterator it = mHistory.begin();
for ( ; it != mHistory.end(); ++it )
- history.append( *it );
+ history.append( *it );
QFile f( QDir::currentDirPath() + "/.history" );
- f.open( IO_WriteOnly );
- QDataStream s( &f );
- s << history;
- f.close();
+ if ( f.open( IO_WriteOnly ) ) {
+ QDataStream s( &f );
+ s << history;
+ f.close();
+ }
bookmarks.clear();
QMap<int, QString>::Iterator it2 = mBookmarks.begin();
for ( ; it2 != mBookmarks.end(); ++it2 )
- bookmarks.append( *it2 );
+ bookmarks.append( *it2 );
QFile f2( QDir::currentDirPath() + "/.bookmarks" );
- f2.open( IO_WriteOnly );
+ if ( !f2.open( IO_WriteOnly ) )
+ return;
+
QDataStream s2( &f2 );
s2 << bookmarks;
f2.close();
}
-// void HelpWindow::about()
-// {
-// QMessageBox::about( this, "Gutenbrowser", "<p>Thanks to Trolltech for this</p>" );
-// }
-
-// void HelpWindow::aboutQt()
-// {
-// QMessageBox::aboutQt( this, "QBrowser" );
-// }
-
void HelpWindow::openFile()
{
#ifndef QT_NO_FILEDIALOG
QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
if ( !fn.isEmpty() )
browser->setSource( fn );
#endif
}
void HelpWindow::newWindow()
{
( new HelpWindow(browser->source(), "qbrowser") )->show();
}
void HelpWindow::print()
{
#ifndef QT_NO_PRINTER
QPrinter printer;
printer.setFullPage(TRUE);
if ( printer.setup() ) {
QPainter p( &printer );
QPaintDeviceMetrics metrics(p.device());
int dpix = metrics.logicalDpiX();
int dpiy = metrics.logicalDpiY();
const int margin = 72; // pt
QRect body(margin*dpix/72, margin*dpiy/72,
metrics.width()-margin*dpix/72*2,
metrics.height()-margin*dpiy/72*2 );
QFont font("times", 10);
QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(),
browser->mimeSourceFactory(), body.height() );
richText.setWidth( &p, body.width() );
QRect view( body );
int page = 1;
do {
p.setClipRect( body );
richText.draw( &p, body.left(), body.top(), view, colorGroup() );
p.setClipping( FALSE );
view.moveBy( 0, body.height() );
p.translate( 0 , -body.height() );
p.setFont( font );
p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
if ( view.top() >= richText.height() )
break;
printer.newPage();
page++;
} while (TRUE);
}
#endif
}
void HelpWindow::pathSelected( const QString &_path )
{
browser->setSource( _path );
QMap<int, QString>::Iterator it = mHistory.begin();
bool exists = FALSE;
for ( ; it != mHistory.end(); ++it ) {
if ( *it == _path ) {
exists = TRUE;
break;
}
}
if ( !exists )
mHistory[ hist->insertItem( _path ) ] = _path;
}
void HelpWindow::readHistory()
{
- if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) {
- QFile f( QDir::currentDirPath() + "/.history" );
- f.open( IO_ReadOnly );
- QDataStream s( &f );
- s >> history;
- f.close();
- while ( history.count() > 20 )
- history.remove( history.begin() );
- }
+ if ( !QFile::exists( QDir::currentDirPath() + "/.history" ) )
+ return;
+
+ QFile f( QDir::currentDirPath() + "/.history" );
+ if ( !f.open( IO_ReadOnly ) )
+ return;
+
+ QDataStream s( &f );
+ s >> history;
+ f.close();
+ while ( history.count() > 20 )
+ history.remove( history.begin() );
}
void HelpWindow::readBookmarks()
{
- if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) {
- QFile f( QDir::currentDirPath() + "/.bookmarks" );
- f.open( IO_ReadOnly );
- QDataStream s( &f );
- s >> bookmarks;
- f.close();
- }
+ if ( !QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) )
+ return;
+
+ QFile f( QDir::currentDirPath() + "/.bookmarks" );
+ if ( !f.open( IO_ReadOnly ) )
+ return;
+ QDataStream s( &f );
+ s >> bookmarks;
+ f.close();
}
void HelpWindow::histChosen( int i )
{
if ( mHistory.contains( i ) )
browser->setSource( mHistory[ i ] );
}
void HelpWindow::bookmChosen( int i )
{
if ( mBookmarks.contains( i ) )
browser->setSource( mBookmarks[ i ] );
}
void HelpWindow::addBookmark()
{
mBookmarks[ bookm->insertItem( caption() ) ] = caption();
}
diff --git a/noncore/graphics/opie-eye/slave/bmp_slave.cpp b/noncore/graphics/opie-eye/slave/bmp_slave.cpp
index 2fa825f..0efadac 100644
--- a/noncore/graphics/opie-eye/slave/bmp_slave.cpp
+++ b/noncore/graphics/opie-eye/slave/bmp_slave.cpp
@@ -1,175 +1,173 @@
#include "bmp_slave.h"
#include "thumbnailtool.h"
#include <qimage.h>
#include <qobject.h>
#include <qfile.h>
#include <qpixmap.h>
#include <qstring.h>
PHUNK_VIEW_INTERFACE( "Bmp", BmpSlave );
namespace {
struct pBmpHeader {
// file header of bmp
char type[2]; // must be "BM" otherwise it is no bmp
Q_INT32 hSize;
Q_INT32 reserved1,reserved2;
Q_INT16 Planes;
Q_INT16 BitCount;
Q_INT32 Size;
Q_INT32 Width;
Q_INT32 Height;
Q_INT32 Compression;
Q_INT32 SizeImage;
Q_INT32 XPerMeter;
Q_INT32 YPerMeter;
Q_INT32 ClrUsed;
Q_INT32 ClrImportant;
};
class BmpHeader {
protected:
void read_data();
QString _name;
QFile _inputfile;
pBmpHeader m_Header;
static const int OLD = 12;
static const int WIN = 40;
static const int OS2 = 64;
static const int RGB = 0;
static const int RLE8 = 1;
static const int RLE4 = 2;
public:
BmpHeader(const QString&fname);
virtual ~BmpHeader();
bool isBmp()const{return qstrncmp(m_Header.type,"BM",2)==0;}
bool isCompressed()const{return m_Header.Compression != 0;}
QSize imageSize(){return QSize(m_Header.Width,m_Header.Height);}
QString imageCompression()const;
int bitsPixel()const{return m_Header.BitCount;}
int Size()const{return m_Header.hSize;}
int compressedSize()const{return m_Header.SizeImage;}
int ColorsUsed()const{return m_Header.ClrUsed;}
int XPix()const{return m_Header.XPerMeter;}
int YPix()const{return m_Header.YPerMeter;}
};
QString BmpHeader::imageCompression()const
{
switch (m_Header.Compression) {
case RLE8:
return "8Bit RLE Encoding";
break;
case RLE4:
return "4Bit RLE Encoding";
break;
case RGB:
default:
return "No encoding";
}
}
BmpHeader::BmpHeader(const QString&fname)
: _name(fname),_inputfile(_name)
{
read_data();
}
void BmpHeader::read_data() {
memset(&m_Header,0,sizeof(pBmpHeader));
- _inputfile.open(IO_Raw|IO_ReadOnly);
- if (!_inputfile.isOpen()) {
+ if (!_inputfile.open(IO_Raw|IO_ReadOnly))
return;
- }
QDataStream s(&_inputfile);
s.setByteOrder( QDataStream::LittleEndian );
s.readRawBytes(m_Header.type,2);
if (!isBmp()) {
_inputfile.close();
return;
}
s >> m_Header.hSize;
s >> m_Header.reserved1 >> m_Header.reserved2;
s >> m_Header.Size;
if ( m_Header.Size == BmpHeader::WIN || m_Header.Size == BmpHeader::OS2 ) {
s >> m_Header.Width >> m_Header.Height >> m_Header.Planes >> m_Header.BitCount;
s >> m_Header.Compression >> m_Header.SizeImage;
s >> m_Header.XPerMeter >> m_Header.YPerMeter;
s >> m_Header.ClrUsed >> m_Header.ClrImportant;
} else {
Q_INT16 w, h;
s >> w >> h >> m_Header.Planes >> m_Header.BitCount;
m_Header.Width = w;
m_Header.Height = h;
m_Header.Compression = BmpHeader::RGB;
m_Header.SizeImage = 0;
m_Header.XPerMeter = m_Header.YPerMeter = 0;
m_Header.ClrUsed = m_Header.ClrImportant = 0;
}
_inputfile.close();
}
BmpHeader::~BmpHeader() {
}
}
BmpSlave::BmpSlave()
: SlaveInterface(QStringList("bmp"))
{}
BmpSlave::~BmpSlave() {
}
QString BmpSlave::iconViewName(const QString& str) {
QString st;
BmpHeader bh(str);
if (!bh.isBmp()) {
st.append("No bmp file");
return st;
}
QSize isize = bh.imageSize();
st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height());
st+=QObject::tr("Size: %1\n").arg(bh.Size());
st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel());
return st;
}
QString BmpSlave::fullImageInfo( const QString& str) {
QString st = "<qt>";
BmpHeader bh(str);
if (!bh.isBmp()) {
st.append("No bmp file");
st.append( "</qt>" );
return st;
}
QSize isize = bh.imageSize();
st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height());
st+=QObject::tr("Size: %1\n").arg(bh.Size());
st+=QObject::tr("Compression: %1\n").arg(bh.imageCompression());
if (bh.isCompressed()) {
st+=QObject::tr("Compressed size: %1").arg(bh.compressedSize());
}
st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel());
st+=QObject::tr("used colors: %1\n").arg(bh.ColorsUsed());
st+=QObject::tr("Resolution: %1 x %2\n").arg(bh.XPix()).arg(bh.YPix());
st.append( "</qt>" );
return st;
}
QPixmap BmpSlave::pixmap(const QString& path, int width, int height ) {
static QImage img;
img.load( path );
if ( img.isNull() ) {
QPixmap pix;
return pix;
}
return ThumbNailTool::scaleImage( img, width,height );
}
diff --git a/noncore/net/ftplib/ftplib.c b/noncore/net/ftplib/ftplib.c
index 421f855..efcd6f0 100644
--- a/noncore/net/ftplib/ftplib.c
+++ b/noncore/net/ftplib/ftplib.c
@@ -865,193 +865,194 @@ GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
case FTPLIB_DIR:
strcpy(buf,"NLST");
dir = FTPLIB_READ;
break;
case FTPLIB_DIR_VERBOSE:
strcpy(buf,"LIST");
dir = FTPLIB_READ;
break;
case FTPLIB_FILE_READ:
strcpy(buf,"RETR");
dir = FTPLIB_READ;
break;
case FTPLIB_FILE_WRITE:
strcpy(buf,"STOR");
dir = FTPLIB_WRITE;
break;
default:
sprintf(nControl->response, "Invalid open type %d\n", typ);
return 0;
}
if (path != NULL)
{
int i = strlen(buf);
buf[i++] = ' ';
if ((strlen(path) + i) >= sizeof(buf))
return 0;
strcpy(&buf[i],path);
}
if (FtpOpenPort(nControl, nData, mode, dir) == -1)
return 0;
if (!FtpSendCmd(buf, '1', nControl))
{
FtpClose(*nData);
*nData = NULL;
return 0;
}
(*nData)->ctrl = nControl;
nControl->data = *nData;
if (nControl->cmode == FTPLIB_PORT)
{
if (!FtpAcceptConnection(*nData,nControl))
{
FtpClose(*nData);
*nData = NULL;
nControl->data = NULL;
return 0;
}
}
return 1;
}
/*
* FtpRead - read from a data connection
*/
GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData)
{
int i;
if (nData->dir != FTPLIB_READ)
return 0;
if (nData->buf)
i = readline(buf, max, nData);
else
{
i = socket_wait(nData);
if (i != 1)
return 0;
i = net_read(nData->handle, buf, max);
}
if (i == -1)
return 0;
nData->xfered += i;
if (nData->idlecb && nData->cbbytes)
{
nData->xfered1 += i;
if (nData->xfered1 > nData->cbbytes)
{
if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0)
return 0;
nData->xfered1 = 0;
}
}
return i;
}
/*
* FtpWrite - write to a data connection
*/
GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData)
{
int i;
if (nData->dir != FTPLIB_WRITE)
return 0;
if (nData->buf)
i = writeline(buf, len, nData);
else
{
- socket_wait(nData);
+ if (socket_wait(nData) < 0)
+ fprintf(stderr, "FtpWrite: socket_wait failed with %s\n", nData->ctrl->response);
i = net_write(nData->handle, buf, len);
}
if (i == -1)
return 0;
nData->xfered += i;
if (nData->idlecb && nData->cbbytes)
{
nData->xfered1 += i;
if (nData->xfered1 > nData->cbbytes)
{
nData->idlecb(nData, nData->xfered, nData->idlearg);
nData->xfered1 = 0;
}
}
return i;
}
/*
* FtpClose - close a data connection
*/
GLOBALDEF int FtpClose(netbuf *nData)
{
netbuf *ctrl;
switch (nData->dir)
{
case FTPLIB_WRITE:
/* potential problem - if buffer flush fails, how to notify user? */
if (nData->buf != NULL)
writeline(NULL, 0, nData);
case FTPLIB_READ:
if (nData->buf)
free(nData->buf);
shutdown(nData->handle,2);
net_close(nData->handle);
ctrl = nData->ctrl;
free(nData);
if (ctrl)
{
ctrl->data = NULL;
return(readresp('2', ctrl));
}
return 1;
case FTPLIB_CONTROL:
if (nData->data)
{
nData->ctrl = NULL;
FtpClose(nData);
}
net_close(nData->handle);
free(nData);
return 0;
}
return 1;
}
/*
* FtpSite - send a SITE command
*
* return 1 if command successful, 0 otherwise
*/
GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl)
{
char buf[256];
if ((strlen(cmd) + 7) > sizeof(buf))
return 0;
sprintf(buf,"SITE %s",cmd);
if (!FtpSendCmd(buf,'2',nControl))
return 0;
return 1;
}
/*
* FtpSysType - send a SYST command
*
* Fills in the user buffer with the remote system type. If more
* information from the response is required, the user can parse
* it out of the response buffer returned by FtpLastResponse().
*
* return 1 if command successful, 0 otherwise
*/
GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl)
{
int l = max;
char *b = buf;
char *s;
if (!FtpSendCmd("SYST",'2',nControl))
return 0;
s = &nControl->response[4];
while ((--l) && (*s != ' '))
*b++ = *s++;
*b++ = '\0';
return 1;
}
/*
@@ -1246,101 +1247,104 @@ GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl)
*size = sz;
else
rv = 0;
}
return rv;
}
/*
* FtpModDate - determine the modification date of a remote file
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl)
{
char buf[256];
int rv = 1;
if ((strlen(path) + 7) > sizeof(buf))
return 0;
sprintf(buf,"MDTM %s",path);
if (!FtpSendCmd(buf,'2',nControl))
rv = 0;
else
strncpy(dt, &nControl->response[4], max);
return rv;
}
/*
* FtpGet - issue a GET command and write received data to output
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpGet(const char *outputfile, const char *path,
char mode, netbuf *nControl)
{
return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode);
}
/*
* FtpPut - issue a PUT command and send data from input
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode,
netbuf *nControl)
{
return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode);
}
/*
* FtpRename - rename a file at remote
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl)
{
char cmd[256];
if (((strlen(src) + 7) > sizeof(cmd)) ||
((strlen(dst) + 7) > sizeof(cmd)))
return 0;
sprintf(cmd,"RNFR %s",src);
if (!FtpSendCmd(cmd,'3',nControl))
return 0;
sprintf(cmd,"RNTO %s",dst);
if (!FtpSendCmd(cmd,'2',nControl))
return 0;
return 1;
}
/*
* FtpDelete - delete a file at remote
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl)
{
char cmd[256];
if ((strlen(fnm) + 7) > sizeof(cmd))
return 0;
sprintf(cmd,"DELE %s",fnm);
if (!FtpSendCmd(cmd,'2', nControl))
return 0;
return 1;
}
/*
* FtpQuit - disconnect from remote
*
* return 1 if successful, 0 otherwise
*/
GLOBALDEF void FtpQuit(netbuf *nControl)
{
if (nControl->dir != FTPLIB_CONTROL)
return;
- FtpSendCmd("QUIT",'2',nControl);
+ if (FtpSendCmd("QUIT",'2',nControl) == 1) {
+ if (ftplib_debug > 2)
+ fprintf(stderr, "FtpQuit: FtpSendCmd(QUIT) failed\n");
+ }
net_close(nControl->handle);
free(nControl->buf);
free(nControl);
}
diff --git a/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp b/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp
index 410d642..2498bf9 100644
--- a/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp
+++ b/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp
@@ -86,186 +86,190 @@ HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* par
QStringList::Iterator it2 = bookmarks.begin();
for ( ; it2 != bookmarks.end(); ++it2 )
mBookmarks[ bookm->insertItem( *it2 ) ] = *it2;
connect( bookm, SIGNAL( activated(int) ),
this, SLOT( bookmChosen(int) ) );
menuBar()->insertItem( tr("&File"), file );
menuBar()->insertItem( tr("&Go"), go );
menuBar()->insertItem( tr( "History" ), hist );
menuBar()->insertItem( tr( "Bookmarks" ), bookm );
// menuBar()->insertSeparator();
// menuBar()->insertItem( tr("&Help"), help );
menuBar()->setItemEnabled( forwardId, FALSE);
menuBar()->setItemEnabled( backwardId, FALSE);
connect( browser, SIGNAL( backwardAvailable(bool) ), this, SLOT( setBackwardAvailable(bool) ) );
connect( browser, SIGNAL( forwardAvailable(bool) ), this, SLOT( setForwardAvailable(bool) ) );
QToolBar* toolbar = new QToolBar( this );
addToolBar( toolbar, "Toolbar");
QToolButton* button;
button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar );
connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
button->setEnabled( FALSE );
button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar );
connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
button->setEnabled( FALSE );
button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar );
toolbar->addSeparator();
pathCombo = new QComboBox( TRUE, toolbar );
connect( pathCombo, SIGNAL( activated(const QString&) ), this, SLOT( pathSelected(const QString&) ) );
toolbar->setStretchableWidget( pathCombo );
// pathCombo->setMaximumWidth(190);
// setRightJustification( TRUE );
// setDockEnabled( Left, FALSE );
// setDockEnabled( Right, FALSE );
pathCombo->insertItem( home_ );
browser->setFocus();
}
void HelpWindow::setBackwardAvailable( bool b)
{
menuBar()->setItemEnabled( backwardId, b);
}
void HelpWindow::setForwardAvailable( bool b)
{
menuBar()->setItemEnabled( forwardId, b);
}
void HelpWindow::textChanged()
{
if ( browser->documentTitle().isNull() ) {
setCaption( "Stockticker Lookup - " + browser->context() );
selectedURL = browser->context();
}
else {
setCaption( "Stockticker Lookup - " + browser->documentTitle() ) ;
selectedURL = browser->documentTitle();
}
if ( !selectedURL.isEmpty() && pathCombo ) {
bool exists = FALSE;
int i;
for ( i = 0; i < pathCombo->count(); ++i ) {
if ( pathCombo->text( i ) == selectedURL ) {
exists = TRUE;
break;
}
}
if ( !exists ) {
pathCombo->insertItem( selectedURL, 0 );
pathCombo->setCurrentItem( 0 );
mHistory[ hist->insertItem( selectedURL ) ] = selectedURL;
} else
pathCombo->setCurrentItem( i );
selectedURL = QString::null;
}
}
HelpWindow::~HelpWindow()
{
history.clear();
QMap<int, QString>::Iterator it = mHistory.begin();
for ( ; it != mHistory.end(); ++it )
- history.append( *it );
+ history.append( *it );
QFile f( QDir::currentDirPath() + "/.history" );
- f.open( IO_WriteOnly );
- QDataStream s( &f );
- s << history;
- f.close();
+ if ( f.open( IO_WriteOnly ) ) {
+ QDataStream s( &f );
+ s << history;
+ f.close();
+ }
bookmarks.clear();
QMap<int, QString>::Iterator it2 = mBookmarks.begin();
for ( ; it2 != mBookmarks.end(); ++it2 )
- bookmarks.append( *it2 );
+ bookmarks.append( *it2 );
QFile f2( QDir::currentDirPath() + "/.bookmarks" );
- f2.open( IO_WriteOnly );
+ if ( !f2.open( IO_WriteOnly ) )
+ return;
QDataStream s2( &f2 );
s2 << bookmarks;
f2.close();
}
void HelpWindow::openFile()
{
#ifndef QT_NO_FILEDIALOG
QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
if ( !fn.isEmpty() )
browser->setSource( fn );
#endif
}
void HelpWindow::newWindow()
{
( new HelpWindow(browser->source(), "qbrowser") )->show();
}
void HelpWindow::pathSelected( const QString &_path )
{
browser->setSource( _path );
QMap<int, QString>::Iterator it = mHistory.begin();
bool exists = FALSE;
for ( ; it != mHistory.end(); ++it ) {
if ( *it == _path ) {
exists = TRUE;
break;
}
}
if ( !exists )
mHistory[ hist->insertItem( _path ) ] = _path;
}
void HelpWindow::readHistory()
{
if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) {
- QFile f( QDir::currentDirPath() + "/.history" );
- f.open( IO_ReadOnly );
- QDataStream s( &f );
- s >> history;
- f.close();
- while ( history.count() > 20 )
- history.remove( history.begin() );
+ QFile f( QDir::currentDirPath() + "/.history" );
+ if ( !f.open( IO_ReadOnly ) )
+ return;
+ QDataStream s( &f );
+ s >> history;
+ f.close();
+ while ( history.count() > 20 )
+ history.remove( history.begin() );
}
}
void HelpWindow::readBookmarks()
{
if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) {
- QFile f( QDir::currentDirPath() + "/.bookmarks" );
- f.open( IO_ReadOnly );
- QDataStream s( &f );
- s >> bookmarks;
- f.close();
+ QFile f( QDir::currentDirPath() + "/.bookmarks" );
+ if ( !f.open( IO_ReadOnly ) )
+ return;
+ QDataStream s( &f );
+ s >> bookmarks;
+ f.close();
}
}
void HelpWindow::histChosen( int i )
{
if ( mHistory.contains( i ) )
browser->setSource( mHistory[ i ] );
}
void HelpWindow::bookmChosen( int i )
{
if ( mBookmarks.contains( i ) )
browser->setSource( mBookmarks[ i ] );
}
void HelpWindow::addBookmark()
{
mBookmarks[ bookm->insertItem( caption() ) ] = caption();
}
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp
index fe54051..27624c5 100644
--- a/noncore/todayplugins/weather/weatherpluginwidget.cpp
+++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp
@@ -11,231 +11,232 @@ _;:, .> :=|. This file is free software; you can
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This file 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 this file;
-_. . . )=. = see the file COPYING. If not, write to the
-- :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/oprocess.h>
#include <opie2/oresource.h>
#include <qpe/config.h>
#include <qfile.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpixmap.h>
#include <qtextstream.h>
#include "weatherpluginwidget.h"
using namespace Opie::Core;
WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name )
: QWidget( parent, name )
{
QHBoxLayout *layout = new QHBoxLayout( this, 1, 2 );
layout->setAutoAdd( true );
weatherIcon = new QLabel( this );
weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( "Clock", Opie::Core::OResource::SmallIcon ) );
weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this );
weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
weatherIcon->setFixedSize( weatherLabel->height(), weatherLabel->height() );
startTimer(1000);
}
WeatherPluginWidget::~WeatherPluginWidget()
{
QFile file( localFile );
if ( file.exists() )
{
file.remove();
}
}
void WeatherPluginWidget::timerEvent( QTimerEvent *e )
{
killTimer( e->timerId() );
retreiveData();
}
void WeatherPluginWidget::retreiveData()
{
Config config( "todayweatherplugin");
config.setGroup( "Config" );
location = config.readEntry( "Location", "" );
useMetric = config.readBoolEntry( "Metric", true );
frequency = config.readNumEntry( "Frequency", 5 );
startTimer( frequency * 60000 );
localFile = "/tmp/";
localFile.append( location );
localFile.append( ".TXT" );
remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/";
remoteFile.append( location );
remoteFile.append( ".TXT" );
QFile file( localFile );
if ( file.exists() )
{
file.remove();
}
OProcess *proc = new OProcess;
*proc << "wget" << "-q" << remoteFile << "-O" << localFile;
connect( proc, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( dataRetrieved(Opie::Core::OProcess*) ) );
- proc->start();
+ if ( !proc->start() )
+ weatherLabel->setText( tr( "Could not start wget process." ) );
}
void WeatherPluginWidget::displayWeather()
{
weatherData = QString::null;
QFile file( localFile );
if ( file.size() > 0 && file.open( IO_ReadOnly ) )
{
QTextStream data( &file );
while ( !data.eof() )
{
weatherData.append( data.readLine() );
}
file.close();
weatherData = weatherData.simplifyWhiteSpace();
QString tmpstr;
tmpstr.append( tr( "Temp: " ) );
getTemp( weatherData );
tmpstr.append( dataStr );
tmpstr.append( tr( " Wind: " ) );
getWind( weatherData );
tmpstr.append( dataStr );
tmpstr.append( tr( "\nPres: " ) );
getPressure( weatherData );
tmpstr.append( dataStr );
weatherLabel->setText( tmpstr );
tmpstr = "todayweatherplugin/";
getIcon( weatherData );
tmpstr.append( dataStr );
- weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( tmpstr, Opie::Core::OResource::SmallIcon ) );
+ weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( tmpstr, Opie::Core::OResource::SmallIcon ) );
}
else
{
weatherLabel->setText( tr( "Current weather data not available." ) );
}
}
void WeatherPluginWidget::getTemp( const QString &data )
{
int value;
bool ok;
int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 );
if ( pos > -1 )
{
if ( data.at( pos ) == 'M' )
{
value = -1 * data.mid( pos + 1, 2 ).toInt( &ok );
}
else
{
value = data.mid( pos, 2 ).toInt( &ok );
}
if ( useMetric )
{
dataStr = QString::number( value );
dataStr.append( 'C' );
}
else
{
dataStr = QString::number( ( value * 9 / 5 ) + 32 );
dataStr.append( 'F' );
}
}
else
{
dataStr = tr( "n/a" );
}
}
void WeatherPluginWidget::getWind( const QString &data )
{
int value;
bool ok;
int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 );
if ( pos > -1 )
{
if ( data.mid( pos, 3 ) != "VRB" )
{
value = data.mid( pos, 3 ).toInt( &ok );
if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) )
dataStr = tr("E " );
else if ( value >= 23 && value < 69 )
dataStr = tr( "NE " );
else if ( value >= 69 && value < 113 )
dataStr = tr( "N " );
else if ( value >= 113 && value < 157 )
dataStr = tr( "NW " );
else if ( value >= 157 && value < 203 )
dataStr = tr( "W " );
else if ( value >= 203 && value < 248 )
dataStr = tr( "SW " );
else if ( value >= 248 && value < 294 )
dataStr = tr( "S " );
else if ( value >= 294 && value < 238 )
dataStr = tr( "SE " );
}
if ( data.mid( pos + 5, 1) == "G" ||
data.mid( pos + 5, 1) == "K" )
{
value = data.mid( pos + 3, 2 ).toInt( &ok );
}
else
{
value = data.mid( pos + 3, 3 ).toInt( &ok );
}
if ( useMetric )
{
value = value * 3.6 / 1.94;
dataStr.append( QString::number( value ) );
dataStr.append( tr( " KPH" ) );
}
else
{
value = value * 2.24 / 1.94;
dataStr.append( QString::number( value ) );
dataStr.append( tr( " MPH" ) );
}
}
else
{
dataStr = tr( "n/a" );
}
}
diff --git a/noncore/tools/opie-sh/inputdialog.cpp b/noncore/tools/opie-sh/inputdialog.cpp
index 8046795..1dd8bf7 100644
--- a/noncore/tools/opie-sh/inputdialog.cpp
+++ b/noncore/tools/opie-sh/inputdialog.cpp
@@ -1,124 +1,128 @@
/*
Opie-sh. convinience app to allow you to use qdialogs in scripts (mainly shell scripts)
Copyright (C) 2002 Thomas Stephens
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.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "inputdialog.h"
InputDialog::InputDialog(int w, int h, int newtype, QString labelString, QString title, QString filename, bool edit, QWidget *parent, const char *name, bool modal, WFlags f):QDialog(parent, name, modal, f)
{
type = newtype;
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addStrut(32);
QLabel *label = new QLabel(labelString, this, "label");
setCaption(title);
int x, y;
layout->addSpacing(5);
layout->addWidget(label);
layout->addSpacing(5);
switch(type)
{
case 0:
lineEdit = new QLineEdit(this, "line edit");
layout->addWidget(lineEdit);
break;
case 1:
comboBox = new QComboBox(edit, this, "combo box");
layout->addWidget(comboBox);
if(!filename.isNull())
{
QFile file(filename);
- file.open(IO_ReadOnly);
- QTextStream stream(&file);
- QString string = stream.read();
+ if (file.open(IO_ReadOnly))
+ {
+ QTextStream stream(&file);
+ QString string = stream.read();
- comboBox->insertStringList(QStringList::split('\n', string));
+ comboBox->insertStringList(QStringList::split('\n', string));
+ }
}
else
{
QFile file;
file.open(IO_ReadOnly, 0);
QTextStream stream(&file);
QString string = stream.read();
comboBox->insertStringList(QStringList::split('\n', string));
}
break;
case 2:
listBox = new QListBox(this, "list box");
listBox->setSelectionMode(QListBox::Multi);
layout->addWidget(listBox);
if(!filename.isNull())
{
QFile file(filename);
- file.open(IO_ReadOnly);
- QTextStream stream(&file);
- QString string = stream.read();
+ if (file.open(IO_ReadOnly))
+ {
+ QTextStream stream(&file);
+ QString string = stream.read();
- listBox->insertStringList(QStringList::split('\n', string));
+ listBox->insertStringList(QStringList::split('\n', string));
+ }
}
else
{
QFile file;
file.open(IO_ReadOnly, 0);
QTextStream stream(&file);
QString string = stream.read();
listBox->insertStringList(QStringList::split('\n', string));
}
break;
case 3:
lineEdit = new QLineEdit(this, "line edit");
lineEdit->setEchoMode(QLineEdit::Password);
layout->addWidget(lineEdit);
break;
}
layout->addSpacing(5);
x=(w/2)-(width()/2);
y=(h/2)-(height()/2);
move(x,y);
}
QString InputDialog::getString()
{
switch (type)
{
case 0:
case 3:
return ((QLineEdit *)child("line edit"))->text();
break;
case 1:
return ((QComboBox *)child("combo box"))->currentText();
break;
case 2:
QString string;
int i;
for(i = 0; i < listBox->count(); i++)
{
if(listBox->isSelected(i))
{
string+=listBox->text(i)+'\n';
}
}
if(string[string.length()-1] == '\n')
{
string.truncate(string.length()-1);
}
return string;
}
return QString::null;
}