summaryrefslogtreecommitdiff
path: root/core/apps/textedit/textedit.cpp
Side-by-side diff
Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp83
1 files changed, 43 insertions, 40 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 5bb65a9..c9178a5 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -8,42 +8,45 @@
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
**********************************************************************/
// changes added by L. J. Potter Sun 02-17-2002 21:31:31
+
#include "textedit.h"
#include "filePermissions.h"
-
+/* OPIE */
+#include <opie2/odebug.h>
#include <opie2/ofileselector.h>
#include <opie2/ofiledialog.h>
#include <opie2/ofontselector.h>
-
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpe/qpeapplication.h>
+using namespace Opie::Core;
+using namespace Opie::Ui;
+
+/* QT */
#include <qmenubar.h>
#include <qtoolbar.h>
-
#include <qtextstream.h>
#include <qclipboard.h>
#include <qaction.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qlayout.h>
#include <qtimer.h>
#include <qdir.h>
+
+/* STD */
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h> //getenv
-using namespace Opie::Ui;
-
#if QT_VERSION < 300
-
class QpeEditor : public QMultiLineEdit
{
public:
QpeEditor( QWidget *parent, const char * name = 0 )
: QMultiLineEdit( parent, name ) {
@@ -408,13 +411,13 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
}
viewSelection = cfg.readNumEntry( "FileView", 0 );
}
TextEdit::~TextEdit() {
- qWarning("textedit d'tor");
+ owarn << "textedit d'tor" << oendl;
delete editor;
}
void TextEdit::closeEvent(QCloseEvent *) {
if( edited1 && promptExit)
{
@@ -643,22 +646,22 @@ void TextEdit::newFile( const DocLnk &f ) {
nf.setType("text/plain");
clear();
setWState (WState_Reserved1 );
editor->setFocus();
doc = new DocLnk(nf);
currentFileName = "Unnamed";
- qDebug("newFile "+currentFileName);
+ odebug << "newFile "+currentFileName << oendl;
updateCaption( currentFileName);
// editor->setEdited( false);
}
void TextEdit::openDotFile( const QString &f ) {
if(!currentFileName.isEmpty()) {
currentFileName=f;
- qDebug("openFile dotfile " + currentFileName);
+ odebug << "openFile dotfile " + currentFileName << oendl;
QString txt;
QFile file(f);
file.open(IO_ReadWrite);
QTextStream t(&file);
while ( !t.atEnd()) {
txt+=t.readLine()+"\n";
@@ -671,13 +674,13 @@ void TextEdit::openDotFile( const QString &f ) {
}
updateCaption( currentFileName);
}
void TextEdit::openFile( const QString &f ) {
- qDebug("filename is "+ f);
+ odebug << "filename is "+ f << oendl;
QString filer;
QFileInfo fi( f);
// bFromDocView = true;
if(f.find(".desktop",0,true) != -1 && !openDesktop )
{
switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) )
@@ -690,13 +693,13 @@ void TextEdit::openFile( const QString &f ) {
filer = sf.file();
break;
};
}
else if(fi.baseName().left(1) == "")
{
- qDebug("opening dotfile");
+ odebug << "opening dotfile" << oendl;
currentFileName=f;
openDotFile(currentFileName);
return;
}
/*
* The problem is a file where Config(f).isValid() and it does not
@@ -718,13 +721,13 @@ void TextEdit::openFile( const QString &f ) {
nf.setFile(filer);
currentFileName=filer;
nf.setName(fi.baseName());
openFile(nf);
- qDebug("openFile string "+currentFileName);
+ odebug << "openFile string "+currentFileName << oendl;
showEditTools();
// Show filename in caption
QString name = filer;
int sep = name.findRev( '/' );
if ( sep > 0 )
@@ -735,16 +738,16 @@ void TextEdit::openFile( const QString &f ) {
void TextEdit::openFile( const DocLnk &f ) {
// clear();
// bFromDocView = true;
FileManager fm;
QString txt;
currentFileName=f.file();
- qDebug("openFile doclnk " + currentFileName);
+ odebug << "openFile doclnk " + currentFileName << oendl;
if ( !fm.loadFile( f, txt ) ) {
// ####### could be a new file
- qDebug( "Cannot open file" );
+ odebug << "Cannot open file" << oendl;
}
// fileNew();
if ( doc )
delete doc;
doc = new DocLnk(f);
editor->setText(txt);
@@ -767,51 +770,51 @@ void TextEdit::showEditTools() {
setWState (WState_Reserved1 );
}
/*!
unprompted save */
bool TextEdit::save() {
- qDebug("saveAsFile " + currentFileName);
+ odebug << "saveAsFile " + currentFileName << oendl;
if(currentFileName.isEmpty()) {
saveAs();
return false;
}
QString file = doc->file();
- qDebug("saver file "+file);
+ odebug << "saver file "+file << oendl;
QString name= doc->name();
- qDebug("File named "+name);
+ odebug << "File named "+name << oendl;
QString rt = editor->text();
if( !rt.isEmpty() ) {
if(name.isEmpty()) {
saveAs();
} else {
currentFileName= name ;
- qDebug("saveFile "+currentFileName);
+ odebug << "saveFile "+currentFileName << oendl;
struct stat buf;
mode_t mode;
stat(file.latin1(), &buf);
mode = buf.st_mode;
if(!fileIs) {
doc->setName( name);
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
- QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
+ QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
return false;
}
} else {
- qDebug("regular save file");
+ odebug << "regular save file" << oendl;
QFile f(file);
if( f.open(IO_WriteOnly)) {
QCString crt = rt.utf8();
f.writeBlock(crt,crt.length());
} else {
QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
- return false;
+ return false;
}
}
editor->setEdited( false);
edited1=false;
edited=false;
@@ -829,32 +832,32 @@ bool TextEdit::save() {
/*!
prompted save */
bool TextEdit::saveAs() {
if(caption() == tr("Text Editor"))
return false;
- qDebug("saveAsFile " + currentFileName);
+ odebug << "saveAsFile " + currentFileName << oendl;
// case of nothing to save...
// if ( !doc && !currentFileName.isEmpty()) {
// //|| !bFromDocView)
-// qDebug("no doc");
+// odebug << "no doc" << oendl;
// return true;
// }
// if ( !editor->edited() ) {
// delete doc;
// doc = 0;
// return true;
// }
QString rt = editor->text();
- qDebug(currentFileName);
+ odebug << currentFileName << oendl;
if( currentFileName.isEmpty()
|| currentFileName == tr("Unnamed")
|| currentFileName == tr("Text Editor")) {
- qDebug("do silly TT filename thing");
+ odebug << "do silly TT filename thing" << oendl;
// if ( doc && doc->name().isEmpty() ) {
QString pt = rt.simplifyWhiteSpace();
int i = pt.find( ' ' );
QString docname = pt;
if ( i > 0 )
docname = pt.left( i );
@@ -869,13 +872,13 @@ bool TextEdit::saveAs() {
if ( docname.isEmpty() )
docname = tr("Unnamed");
if(doc) doc->setName(docname);
currentFileName=docname;
// }
// else
-// qDebug("hmmmmmm");
+// odebug << "hmmmmmm" << oendl;
}
QMap<QString, QStringList> map;
map.insert(tr("All"), QStringList() );
QStringList text;
@@ -897,31 +900,31 @@ bool TextEdit::saveAs() {
} else
str=currentFileName;
if(!str.isEmpty()) {
QString fileNm=str;
- qDebug("saving filename "+fileNm);
+ odebug << "saving filename "+fileNm << oendl;
QFileInfo fi(fileNm);
currentFileName=fi.fileName();
if(doc)
// QString file = doc->file();
// doc->removeFiles();
delete doc;
DocLnk nf;
nf.setType("text/plain");
nf.setFile( fileNm);
doc = new DocLnk(nf);
// editor->setText(rt);
- qDebug("Saving file as "+currentFileName);
+ odebug << "Saving file as "+currentFileName << oendl;
doc->setName( currentFileName);
updateCaption( currentFileName);
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
- QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
+ QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
return false;
}
if( filePerms ) {
filePermissions *filePerm;
filePerm = new filePermissions(this,
@@ -938,13 +941,13 @@ bool TextEdit::saveAs() {
edited = false;
if(caption().left(1)=="*")
setCaption(caption().right(caption().length()-1));
return true;
}
- qDebug("returning false");
+ odebug << "returning false" << oendl;
return false;
} //end saveAs
void TextEdit::clear() {
delete doc;
doc = 0;
@@ -969,20 +972,20 @@ void TextEdit::updateCaption( const QString &name ) {
}
}
void TextEdit::setDocument(const QString& fileref) {
if(fileref != "Unnamed") {
currentFileName=fileref;
- qDebug("setDocument");
+ odebug << "setDocument" << oendl;
QFileInfo fi(currentFileName);
- qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName);
+ odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl;
if( (fi.baseName().left(1)).isEmpty() ) {
openDotFile(currentFileName);
} else {
- qDebug("setDoc open");
+ odebug << "setDoc open" << oendl;
bFromDocView = true;
openFile(fileref);
editor->setEdited(true);
edited1=false;
edited=true;
// fromSetDocument=false;
@@ -1031,24 +1034,24 @@ void TextEdit::changeStartConfig( bool b ) {
cfg.setGroup("View");
cfg.writeEntry("startNew",b);
update();
}
void TextEdit::editorChanged() {
-// qDebug("editor changed");
+// odebug << "editor changed" << oendl;
if( /*editor->edited() &&*/ /*edited && */!edited1) {
setCaption( "*"+caption());
edited1=true;
}
edited=true;
}
void TextEdit::receive(const QCString&msg, const QByteArray &) {
- qDebug("QCop "+msg);
+ odebug << "QCop "+msg << oendl;
if ( msg == "setDocument(QString)" ) {
- qDebug("bugger all");
+ odebug << "bugger all" << oendl;
}
}
void TextEdit::doAbout() {
@@ -1126,13 +1129,13 @@ void TextEdit::timerCrank()
{
currentFileName = QDir::homeDirPath()+"/textedit.tmp";
saveAs();
}
else
{
-// qDebug("autosave");
+// odebug << "autosave" << oendl;
save();
}
setTimer();
}
}
@@ -1142,24 +1145,24 @@ void TextEdit::doTimer(bool b)
cfg.setGroup ( "View" );
cfg.writeEntry ( "autosave", b);
featureAutoSave = b;
nAutoSave->setOn(b);
if(b)
{
-// qDebug("doTimer true");
+// odebug << "doTimer true" << oendl;
setTimer();
}
// else
-// qDebug("doTimer false");
+// odebug << "doTimer false" << oendl;
}
void TextEdit::setTimer()
{
if(featureAutoSave)
{
-// qDebug("setting autosave");
+// odebug << "setting autosave" << oendl;
QTimer *timer = new QTimer(this );
connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) );
timer->start( 300000, true); //5 minutes
}
}