summaryrefslogtreecommitdiff
path: root/noncore/applets/notesapplet
authoralwin <alwin>2004-03-02 12:21:11 (UTC)
committer alwin <alwin>2004-03-02 12:21:11 (UTC)
commitb6b1c97559c0ed9f2e33632272426bf98f289232 (patch) (side-by-side diff)
treed3a9987704770cdf5eb14e1136f6e3ecb2f36a04 /noncore/applets/notesapplet
parent0d59c780513da78033f4d9040475dee9db0256d4 (diff)
downloadopie-b6b1c97559c0ed9f2e33632272426bf98f289232.zip
opie-b6b1c97559c0ed9f2e33632272426bf98f289232.tar.gz
opie-b6b1c97559c0ed9f2e33632272426bf98f289232.tar.bz2
applied the patch generated by the optimize_connect script from
TT.
Diffstat (limited to 'noncore/applets/notesapplet') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/notesapplet/notes.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index 1142028..9b5e475 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -34,288 +34,288 @@
#include <qpopupmenu.h>
#include <qmessagebox.h>
#include <qdir.h>
#include <qfile.h>
#include <qpoint.h>
#include <qpushbutton.h>
#include <qpainter.h>
#include <qlayout.h>
#include <qframe.h>
#include <qpixmap.h>
#include <qstring.h>
#include <qtimer.h>
/* XPM */
static char * notes_xpm[] = {
"16 16 11 1",
" c None",
". c #000000",
"+ c #7F7F7F",
"@ c #BFBFBF",
"# c #BFC1FF",
"$ c #FF0000",
"% c #FFFFFF",
"& c #00037F",
"* c #0006FF",
"= c #0005BF",
"- c #7F0000",
" .. ",
" .. ",
" ... ",
" .+ ",
" .@. ",
" . .+ ",
" ..#.@. ",
" ..###.+.. ",
" ..###$...##.. ",
"..###$$$%+$$##&.",
".*=####$-###&=&.",
".=**=###==&=&=..",
" ..=**=#&=&=.. ",
" ..=*=&=.. ",
" ..=.. ",
" . "};
NotesControl::NotesControl( QWidget *, const char * )
: QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop )
// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
{
QDir d( QDir::homeDirPath()+"/notes");
if( !d.exists()) {
qDebug("make dir");
if(!d.mkdir( QDir::homeDirPath()+"/notes", true))
qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed");
}
Config cfg("Notes");
cfg.setGroup("Options");
showMax = cfg.readBoolEntry("ShowMax", false);
setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
loaded=false;
edited=false;
doPopulate=true;
isNew=false;
QVBox *vbox = new QVBox( this, "Vlayout" );
QHBox *hbox = new QHBox( this, "HLayout" );
view = new QMultiLineEdit(vbox, "OpieNotesView");
box = new QListBox(vbox, "OpieNotesBox");
QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold);
box->setFixedHeight(50);
vbox->setMargin( 6 );
vbox->setSpacing( 3 );
setFocusPolicy(QWidget::StrongFocus);
newButton= new QPushButton( hbox, "newButton" );
newButton->setText(tr("New"));
saveButton= new QPushButton( hbox, "saveButton" );
saveButton->setText(tr("Save"));
deleteButton= new QPushButton( hbox, "deleteButton" );
deleteButton->setText(tr("Delete"));
- connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)),
- this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) );
+ connect( box, SIGNAL( mouseButtonPressed(int,QListBoxItem*,const QPoint&)),
+ this,SLOT( boxPressed(int,QListBoxItem*,const QPoint&)) );
- connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &)));
+ connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString&)));
connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) );
connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) );
connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton()));
connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton()));
connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked()));
populateBox();
load();
setCaption("Notes");
// parent->setFocus();
}
void NotesControl::slotSaveButton() {
slotNewButton();
populateBox();
}
void NotesControl::slotDeleteButtonClicked() {
switch ( QMessageBox::warning(this,tr("Delete?")
,tr("Do you really want to<BR><B> delete</B> this note ?")
,tr("Yes"),tr("No"),0,1,1) ) {
case 0:
slotDeleteButton();
break;
};
}
void NotesControl::slotDeleteButton() {
QString selectedText = box->currentText();
qDebug("deleting "+selectedText);
if( !selectedText.isEmpty()) {
Config cfg("Notes");
cfg.setGroup("Docs");
int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
QString entryName, entryName2;;
for ( int i = 0; i < noOfFiles; i++ ) {
entryName.sprintf( "File%i", i + 1 );
if(selectedText == cfg.readEntry( entryName )) {
qDebug("removing %s, %d", selectedText.latin1(), i);
for ( int j = i; j < noOfFiles; j++ ) {
entryName.sprintf( "File%i", i + 1 );
entryName2.sprintf( "File%i", i + 2 );
QString temp = cfg.readEntry(entryName2);
qDebug("move "+temp);
cfg.writeEntry(entryName, temp);
i++;
}
cfg.writeEntry("NumberOfFiles", noOfFiles-1 );
entryName.sprintf( "File%i", noOfFiles );
cfg.removeEntry(entryName);
cfg.write();
DocLnk nf(selectedText);
nf.removeFiles();
QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop";
qDebug(fi);
QFile f( fi);
if( !f.remove()) qDebug(".desktop file not removed");
}
}
view->clear();
populateBox();
}
}
void NotesControl::slotNewButton() {
if(edited) save();
view->clear();
view->setFocus();
edited=false;
isNew=false;
}
void NotesControl::slotBeamButton() {
Ir ir;
if(!ir.supported()){
} else {
this->hide();
QString selectedText = box->currentText();
if( !selectedText.isEmpty()) {
QString file = QDir::homeDirPath()+"/"+selectedText;
QFile f(file);
Ir *irFile = new Ir(this, "IR");
- connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished( Ir * )));
+ connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished(Ir*)));
irFile->send( file, "Note", "text/plain" );
}
}
}
void NotesControl::slotBeamFinished(Ir *) {
this->show();
}
void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) {
switch (mouse) {
case 1:{
}
break;
case 2:
menuTimer.start( 500, TRUE );
break;
};
}
void NotesControl::slotBoxSelected(const QString &itemString) {
if(edited) {
save();
}
loaded=false;
edited=false;
load(itemString);
}
void NotesControl::showMenu() {
QPopupMenu *m = new QPopupMenu(0);
m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() ));
m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() ));
m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() ));
m->insertSeparator();
m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() ));
m->setFocus();
m->exec( QCursor::pos() );
if(m) delete m;
}
void NotesControl::focusOutEvent ( QFocusEvent * e) {
if( e->reason() == QFocusEvent::Popup)
save();
else {
if(!loaded) {
populateBox();
load();
}
}
QWidget::focusOutEvent(e);
}
void NotesControl::save() {
Config cfg("Notes");
cfg.setGroup("Docs");
if( edited) {
// qDebug("is edited");
QString rt = view->text();
if( rt.length()>1) {
QString pt = rt.simplifyWhiteSpace();
int i = pt.find( ' ', pt.find( ' ' )+2 );
QString docname = pt;
if ( i > 0 )
docname = pt.left(i);
// remove "." at the beginning
while( docname.startsWith( "." ) )
docname = docname.mid( 1 );
docname.replace( QRegExp("/"), "_" );
// cut the length. filenames longer than that don't make sense
// and something goes wrong when they get too long.
if ( docname.length() > 40 )
docname = docname.left(40);
if ( docname.isEmpty() )
docname = "Empty Text";
// qDebug(docname);
if( oldDocName != docname) {
int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
QString entryName;
entryName.sprintf( "File%i", noOfFiles + 1 );
cfg.writeEntry( entryName,docname );
cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
cfg.write();
}
// else
// qDebug("oldname equals docname");
doc = new DocLnk(docname);
if(QFile(doc->linkFile()).exists())
qDebug("puppie");
doc->setType("text/plain");
doc->setName(docname);
QString temp = docname.replace( QRegExp(" "), "_" );