author | llornkcor <llornkcor> | 2002-11-16 05:28:00 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-16 05:28:00 (UTC) |
commit | 9591a32654e5189841b9a6d60e7bf235b1b0fa4b (patch) (unidiff) | |
tree | 8a8251b3af82ad830d5d7bc85cd39aea68e505d8 | |
parent | b17b2274c200403da25a994ed9d8ba4856d725c0 (diff) | |
download | opie-9591a32654e5189841b9a6d60e7bf235b1b0fa4b.zip opie-9591a32654e5189841b9a6d60e7bf235b1b0fa4b.tar.gz opie-9591a32654e5189841b9a6d60e7bf235b1b0fa4b.tar.bz2 |
moved input to output, switched all systems calls to OProcess. got rid of popen
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.h | 3 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.pro | 4 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 215 | ||||
-rw-r--r-- | noncore/apps/advancedfm/inputDialog.cpp | 44 | ||||
-rw-r--r-- | noncore/apps/advancedfm/inputDialog.h | 35 | ||||
-rw-r--r-- | noncore/apps/advancedfm/output.cpp | 142 | ||||
-rw-r--r-- | noncore/apps/advancedfm/output.h | 32 |
7 files changed, 274 insertions, 201 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.h b/noncore/apps/advancedfm/advancedfm.h index 7bccce9..9948255 100644 --- a/noncore/apps/advancedfm/advancedfm.h +++ b/noncore/apps/advancedfm/advancedfm.h | |||
@@ -149,6 +149,9 @@ protected slots: | |||
149 | 149 | ||
150 | private: | 150 | private: |
151 | QTimer menuTimer; | 151 | QTimer menuTimer; |
152 | void startProcess(const QString &); | ||
153 | private slots: | ||
154 | void processEnded(); | ||
152 | }; | 155 | }; |
153 | 156 | ||
154 | #endif // ADVANCEDFM_H | 157 | #endif // ADVANCEDFM_H |
diff --git a/noncore/apps/advancedfm/advancedfm.pro b/noncore/apps/advancedfm/advancedfm.pro index bda2fdf..0e037a1 100644 --- a/noncore/apps/advancedfm/advancedfm.pro +++ b/noncore/apps/advancedfm/advancedfm.pro | |||
@@ -1,7 +1,7 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE = app |
2 | CONFIG += qt warn_on release | 2 | CONFIG += qt warn_on release |
3 | HEADERS = advancedfm.h inputDialog.h filePermissions.h output.h | 3 | HEADERS = advancedfm.h filePermissions.h output.h |
4 | SOURCES = advancedfm.cpp advancedfmData.cpp advancedfmMenu.cpp inputDialog.cpp filePermissions.cpp output.cpp main.cpp | 4 | SOURCES = advancedfm.cpp advancedfmData.cpp advancedfmMenu.cpp filePermissions.cpp output.cpp main.cpp |
5 | TARGET = advancedfm | 5 | TARGET = advancedfm |
6 | INCLUDEPATH += $(OPIEDIR)/include | 6 | INCLUDEPATH += $(OPIEDIR)/include |
7 | DEPENDPATH += $(OPIEDIR)/include | 7 | DEPENDPATH += $(OPIEDIR)/include |
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index f89ad30..0a9f921 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp | |||
@@ -10,11 +10,11 @@ | |||
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | ***************************************************************************/ | 11 | ***************************************************************************/ |
12 | #include "advancedfm.h" | 12 | #include "advancedfm.h" |
13 | #include "inputDialog.h" | ||
14 | #include "output.h" | 13 | #include "output.h" |
15 | #include "filePermissions.h" | 14 | #include "filePermissions.h" |
16 | 15 | ||
17 | #include <opie/otabwidget.h> | 16 | #include <opie/otabwidget.h> |
17 | #include <opie/oprocess.h> | ||
18 | 18 | ||
19 | #include <qpe/lnkproperties.h> | 19 | #include <qpe/lnkproperties.h> |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
@@ -233,7 +233,7 @@ void AdvancedFm::localDelete() { | |||
233 | case 0: { | 233 | case 0: { |
234 | f=f.left(f.length()-1); | 234 | f=f.left(f.length()-1); |
235 | QString cmd="rm -rf "+f; | 235 | QString cmd="rm -rf "+f; |
236 | system( cmd.latin1()); | 236 | startProcess( (const QString)cmd.latin1() ); |
237 | populateLocalView(); | 237 | populateLocalView(); |
238 | } | 238 | } |
239 | break; | 239 | break; |
@@ -255,7 +255,6 @@ void AdvancedFm::localDelete() { | |||
255 | QFile file(f); | 255 | QFile file(f); |
256 | if(QFileInfo(myFile).fileName().find("../",0,TRUE)==-1) | 256 | if(QFileInfo(myFile).fileName().find("../",0,TRUE)==-1) |
257 | file.remove(); | 257 | file.remove(); |
258 | // system( cmd.latin1()); | ||
259 | } | 258 | } |
260 | } | 259 | } |
261 | } | 260 | } |
@@ -298,7 +297,7 @@ void AdvancedFm::remoteDelete() { | |||
298 | case 0: { | 297 | case 0: { |
299 | f=f.left(f.length()-1); | 298 | f=f.left(f.length()-1); |
300 | QString cmd="rm -rf "+f; | 299 | QString cmd="rm -rf "+f; |
301 | system( cmd.latin1()); | 300 | startProcess( (const QString)cmd ); |
302 | populateRemoteView(); | 301 | populateRemoteView(); |
303 | } | 302 | } |
304 | break; | 303 | break; |
@@ -320,7 +319,6 @@ void AdvancedFm::remoteDelete() { | |||
320 | QFile file(f); | 319 | QFile file(f); |
321 | if(QFileInfo(myFile).fileName().find("../",0,TRUE)==-1) | 320 | if(QFileInfo(myFile).fileName().find("../",0,TRUE)==-1) |
322 | file.remove(); | 321 | file.remove(); |
323 | // system( cmd.latin1()); | ||
324 | } | 322 | } |
325 | } | 323 | } |
326 | } | 324 | } |
@@ -810,49 +808,35 @@ bool AdvancedFm::copyFile( const QString & dest, const QString & src ) { | |||
810 | } | 808 | } |
811 | 809 | ||
812 | void AdvancedFm::runCommand() { | 810 | void AdvancedFm::runCommand() { |
813 | QString curFile; | 811 | QString curFile; |
814 | if (TabWidget->getCurrentTab() == 0) { | 812 | if (TabWidget->getCurrentTab() == 0) { |
815 | if( Local_View->currentItem()) | 813 | if( Local_View->currentItem()) |
816 | curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0); | 814 | curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0); |
817 | } else { | ||
818 | if(Remote_View->currentItem()) | ||
819 | curFile = currentRemoteDir.canonicalPath() + "/"+Remote_View->currentItem()->text(0); | ||
820 | } | ||
821 | |||
822 | InputDialog *fileDlg; | ||
823 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | ||
824 | fileDlg->setInputText(curFile); | ||
825 | fileDlg->exec(); | ||
826 | QString command; | ||
827 | if( fileDlg->result() == 1 ) { | ||
828 | command = fileDlg->LineEdit1->text(); | ||
829 | |||
830 | Output *outDlg; | ||
831 | outDlg = new Output(this, tr("AdvancedFm Output"),FALSE); | ||
832 | outDlg->showMaximized(); | ||
833 | outDlg->show(); | ||
834 | qApp->processEvents(); | ||
835 | FILE *fp; | ||
836 | char line[130]; | ||
837 | sleep(1); | ||
838 | command +=" 2>&1"; | ||
839 | fp = popen( (const char *) command, "r"); | ||
840 | if ( !fp ) { | ||
841 | qDebug("Could not execute '" + command + "'! err=%d", fp); | ||
842 | QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); | ||
843 | pclose(fp); | ||
844 | return; | ||
845 | } else { | 815 | } else { |
846 | while ( fgets( line, sizeof line, fp)) { | 816 | if(Remote_View->currentItem()) |
847 | QString lineStr = line; | 817 | curFile = currentRemoteDir.canonicalPath() + "/"+Remote_View->currentItem()->text(0); |
848 | lineStr=lineStr.left(lineStr.length()-1); | ||
849 | outDlg->OutputEdit->append(lineStr); | ||
850 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
851 | } | ||
852 | } | 818 | } |
853 | pclose(fp); | ||
854 | 819 | ||
855 | } | 820 | InputDialog *fileDlg; |
821 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | ||
822 | fileDlg->setInputText(curFile); | ||
823 | fileDlg->exec(); | ||
824 | //QString command; | ||
825 | |||
826 | if( fileDlg->result() == 1 ) { | ||
827 | qDebug(fileDlg->LineEdit1->text()); | ||
828 | QStringList command; | ||
829 | |||
830 | command << "/bin/sh"; | ||
831 | command << "-c"; | ||
832 | command << fileDlg->LineEdit1->text(); | ||
833 | Output *outDlg; | ||
834 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | ||
835 | outDlg->showMaximized(); | ||
836 | outDlg->exec(); | ||
837 | qApp->processEvents(); | ||
838 | |||
839 | } | ||
856 | } | 840 | } |
857 | 841 | ||
858 | void AdvancedFm::runCommandStd() { | 842 | void AdvancedFm::runCommandStd() { |
@@ -870,11 +854,10 @@ void AdvancedFm::runCommandStd() { | |||
870 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 854 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
871 | fileDlg->setInputText(curFile); | 855 | fileDlg->setInputText(curFile); |
872 | fileDlg->exec(); | 856 | fileDlg->exec(); |
873 | QString command; | 857 | |
874 | if( fileDlg->result() == 1 ) { | 858 | if( fileDlg->result() == 1 ) { |
875 | qApp->processEvents(); | 859 | qApp->processEvents(); |
876 | command = fileDlg->LineEdit1->text() + " &"; | 860 | startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); |
877 | system(command.latin1()); | ||
878 | } | 861 | } |
879 | } | 862 | } |
880 | 863 | ||
@@ -885,32 +868,46 @@ void AdvancedFm::fileStatus() { | |||
885 | } else { | 868 | } else { |
886 | curFile = Remote_View->currentItem()->text(0); | 869 | curFile = Remote_View->currentItem()->text(0); |
887 | } | 870 | } |
888 | QString command = " stat -l "+ curFile +" 2>&1"; | ||
889 | Output *outDlg; | ||
890 | outDlg = new Output(this, tr("AdvancedFm Output"),FALSE); | ||
891 | outDlg->showMaximized(); | ||
892 | outDlg->show(); | ||
893 | qApp->processEvents(); | ||
894 | FILE *fp; | ||
895 | char line[130]; | ||
896 | sleep(1); | ||
897 | fp = popen( (const char *) command, "r"); | ||
898 | if ( !fp ) { | ||
899 | qDebug("Could not execute '" + command + "'! err=%d", fp); | ||
900 | QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); | ||
901 | pclose(fp); | ||
902 | return; | ||
903 | } else { | ||
904 | while ( fgets( line, sizeof line, fp)) { | ||
905 | outDlg->OutputEdit->append(line); | ||
906 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
907 | 871 | ||
908 | } | 872 | QStringList command; |
873 | command << "/bin/sh"; | ||
874 | command << "-c"; | ||
875 | command << "stat -l "+ curFile; | ||
909 | 876 | ||
910 | } | 877 | Output *outDlg; |
911 | pclose(fp); | 878 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
879 | outDlg->showMaximized(); | ||
880 | outDlg->exec(); | ||
881 | qApp->processEvents(); | ||
882 | |||
883 | |||
884 | // Output *outDlg; | ||
885 | // outDlg = new Output(this, tr("AdvancedFm Output"),FALSE); | ||
886 | // outDlg->showMaximized(); | ||
887 | // outDlg->show(); | ||
888 | // qApp->processEvents(); | ||
889 | |||
890 | // FILE *fp; | ||
891 | // char line[130]; | ||
892 | // sleep(1); | ||
893 | // fp = popen( (const char *) command, "r"); | ||
894 | // if ( !fp ) { | ||
895 | // qDebug("Could not execute '" + command + "'! err=%d", fp); | ||
896 | // QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); | ||
897 | // pclose(fp); | ||
898 | // return; | ||
899 | // } else { | ||
900 | // while ( fgets( line, sizeof line, fp)) { | ||
901 | // outDlg->OutputEdit->append(line); | ||
902 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
903 | |||
904 | // } | ||
905 | |||
906 | // } | ||
907 | // pclose(fp); | ||
912 | } | 908 | } |
913 | 909 | ||
910 | |||
914 | void AdvancedFm::mkDir() { | 911 | void AdvancedFm::mkDir() { |
915 | if (TabWidget->getCurrentTab() == 0) | 912 | if (TabWidget->getCurrentTab() == 0) |
916 | localMakDir(); | 913 | localMakDir(); |
@@ -935,39 +932,39 @@ void AdvancedFm::del() { | |||
935 | } | 932 | } |
936 | 933 | ||
937 | void AdvancedFm::mkSym() { | 934 | void AdvancedFm::mkSym() { |
938 | QString cmd; | 935 | QString cmd; |
939 | QStringList curFileList = getPath(); | 936 | QStringList curFileList = getPath(); |
940 | if( curFileList.count() > 0) { | 937 | if( curFileList.count() > 0) { |
941 | 938 | ||
942 | if (TabWidget->getCurrentTab() == 0) { | 939 | if (TabWidget->getCurrentTab() == 0) { |
943 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 940 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
944 | 941 | ||
945 | QString destName = currentRemoteDir.canonicalPath()+"/"+(*it); | 942 | QString destName = currentRemoteDir.canonicalPath()+"/"+(*it); |
946 | if(destName.right(1) == "/") destName = destName.left( destName.length() -1); | 943 | if(destName.right(1) == "/") destName = destName.left( destName.length() -1); |
947 | QString curFile = currentDir.canonicalPath()+"/"+(*it); | 944 | QString curFile = currentDir.canonicalPath()+"/"+(*it); |
948 | if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1); | 945 | if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1); |
949 | cmd = "ln -s "+curFile+" "+destName; | 946 | cmd = "ln -s "+curFile+" "+destName; |
950 | qDebug(cmd); | 947 | qDebug(cmd); |
951 | system(cmd.latin1() ); | 948 | startProcess( (const QString)cmd ); |
952 | } | 949 | } |
953 | populateRemoteView(); | 950 | populateRemoteView(); |
954 | TabWidget->setCurrentTab(1); | 951 | TabWidget->setCurrentTab(1); |
955 | } else { | 952 | } else { |
956 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 953 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
957 | 954 | ||
958 | QString destName = currentDir.canonicalPath()+"/"+(*it); | 955 | QString destName = currentDir.canonicalPath()+"/"+(*it); |
959 | if(destName.right(1) == "/") destName = destName.left( destName.length() -1); | 956 | if(destName.right(1) == "/") destName = destName.left( destName.length() -1); |
960 | QString curFile = currentRemoteDir.canonicalPath()+"/"+(*it); | 957 | QString curFile = currentRemoteDir.canonicalPath()+"/"+(*it); |
961 | if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1); | 958 | if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1); |
962 | 959 | ||
963 | cmd = "ln -s "+curFile+" "+destName; | 960 | cmd = "ln -s "+curFile+" "+destName; |
964 | qDebug(cmd); | 961 | qDebug(cmd); |
965 | system(cmd.latin1() ); | 962 | startProcess( (const QString)cmd ); |
966 | } | 963 | } |
967 | populateLocalView(); | 964 | populateLocalView(); |
968 | TabWidget->setCurrentTab(0); | 965 | TabWidget->setCurrentTab(0); |
966 | } | ||
969 | } | 967 | } |
970 | } | ||
971 | } | 968 | } |
972 | 969 | ||
973 | void AdvancedFm::doBeam() { | 970 | void AdvancedFm::doBeam() { |
@@ -1018,3 +1015,23 @@ void AdvancedFm::selectAll() { | |||
1018 | Remote_View->setSelected( Remote_View->firstChild(),false); | 1015 | Remote_View->setSelected( Remote_View->firstChild(),false); |
1019 | } | 1016 | } |
1020 | } | 1017 | } |
1018 | |||
1019 | void AdvancedFm::startProcess(const QString & cmd) { | ||
1020 | QStringList command; | ||
1021 | OProcess *process; | ||
1022 | process = new OProcess(); | ||
1023 | connect(process, SIGNAL(processExited(OProcess *)), | ||
1024 | this, SLOT( processEnded())); | ||
1025 | |||
1026 | command << "/bin/sh"; | ||
1027 | command << "-c"; | ||
1028 | command << cmd.latin1(); | ||
1029 | *process << command; | ||
1030 | if(!process->start(OProcess::NotifyOnExit) ) | ||
1031 | qDebug("could not start process"); | ||
1032 | } | ||
1033 | |||
1034 | void AdvancedFm::processEnded() { | ||
1035 | populateLocalView(); | ||
1036 | populateRemoteView(); | ||
1037 | } | ||
diff --git a/noncore/apps/advancedfm/inputDialog.cpp b/noncore/apps/advancedfm/inputDialog.cpp deleted file mode 100644 index 5af0f72..0000000 --- a/noncore/apps/advancedfm/inputDialog.cpp +++ b/dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | /**************************************************************************** | ||
2 | inputDialog.cpp | ||
3 | ------------------- | ||
4 | ** Created: Sat Mar 9 23:33:09 2002 | ||
5 | copyright : (C) 2002 by ljp | ||
6 | email : ljp@llornkcor.com | ||
7 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | ||
11 | ***************************************************************************/ | ||
12 | |||
13 | #include "inputDialog.h" | ||
14 | |||
15 | #include <qlineedit.h> | ||
16 | #include <qlayout.h> | ||
17 | #include <qvariant.h> | ||
18 | #include <qtooltip.h> | ||
19 | #include <qwhatsthis.h> | ||
20 | |||
21 | |||
22 | InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) | ||
23 | : QDialog( parent, name, modal, fl ) | ||
24 | { | ||
25 | if ( !name ) | ||
26 | setName( "InputDialog" ); | ||
27 | resize( 234, 50 ); | ||
28 | setMaximumSize( QSize( 240, 50 ) ); | ||
29 | setCaption( tr(name ) ); | ||
30 | |||
31 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); | ||
32 | LineEdit1->setGeometry( QRect( 10, 10, 216, 22 ) ); | ||
33 | } | ||
34 | |||
35 | InputDialog::~InputDialog() | ||
36 | { | ||
37 | inputText = LineEdit1->text(); | ||
38 | |||
39 | } | ||
40 | |||
41 | void InputDialog::setInputText(const QString &string) | ||
42 | { | ||
43 | LineEdit1->setText( string); | ||
44 | } | ||
diff --git a/noncore/apps/advancedfm/inputDialog.h b/noncore/apps/advancedfm/inputDialog.h deleted file mode 100644 index 114a3a8..0000000 --- a/noncore/apps/advancedfm/inputDialog.h +++ b/dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | inputDialog.h | ||
3 | ------------------- | ||
4 | ** Created: Sat Mar 9 23:33:09 2002 | ||
5 | copyright : (C) 2002 by ljp | ||
6 | email : ljp@llornkcor.com | ||
7 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | ||
11 | ***************************************************************************/ | ||
12 | #ifndef INPUTDIALOG_H | ||
13 | #define INPUTDIALOG_H | ||
14 | |||
15 | #include <qvariant.h> | ||
16 | #include <qdialog.h> | ||
17 | class QVBoxLayout; | ||
18 | class QHBoxLayout; | ||
19 | class QGridLayout; | ||
20 | class QLineEdit; | ||
21 | |||
22 | class InputDialog : public QDialog | ||
23 | { | ||
24 | Q_OBJECT | ||
25 | |||
26 | public: | ||
27 | InputDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); | ||
28 | ~InputDialog(); | ||
29 | QString inputText; | ||
30 | QLineEdit* LineEdit1; | ||
31 | void setInputText(const QString &); | ||
32 | |||
33 | }; | ||
34 | |||
35 | #endif // INPUTDIALOG_H | ||
diff --git a/noncore/apps/advancedfm/output.cpp b/noncore/apps/advancedfm/output.cpp index 82e78a7..946d038 100644 --- a/noncore/apps/advancedfm/output.cpp +++ b/noncore/apps/advancedfm/output.cpp | |||
@@ -4,20 +4,25 @@ | |||
4 | ** Copyright: Fri Apr 12 15:12:58 2002 L.J. Potter <ljp@llornkcor.com> | 4 | ** Copyright: Fri Apr 12 15:12:58 2002 L.J. Potter <ljp@llornkcor.com> |
5 | ****************************************************************************/ | 5 | ****************************************************************************/ |
6 | #include "output.h" | 6 | #include "output.h" |
7 | #include "inputDialog.h" | 7 | |
8 | #include <opie/oprocess.h> | ||
8 | 9 | ||
9 | #include <qpe/filemanager.h> | 10 | #include <qpe/filemanager.h> |
10 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
11 | #include <qpe/applnk.h> | 12 | #include <qpe/applnk.h> |
12 | 13 | ||
14 | #include <qmessagebox.h> | ||
15 | #include <qstringlist.h> | ||
13 | #include <qfile.h> | 16 | #include <qfile.h> |
14 | 17 | #include <qcstring.h> | |
15 | #include <qlineedit.h> | 18 | #include <qlineedit.h> |
16 | #include <qmultilineedit.h> | 19 | #include <qmultilineedit.h> |
17 | #include <qpushbutton.h> | 20 | #include <qpushbutton.h> |
18 | #include <qlayout.h> | 21 | #include <qlayout.h> |
19 | #include <qvariant.h> | 22 | #include <qvariant.h> |
20 | 23 | ||
24 | #include <errno.h> | ||
25 | |||
21 | /* XPM */ | 26 | /* XPM */ |
22 | static char * filesave_xpm[] = { | 27 | static char * filesave_xpm[] = { |
23 | "16 16 78 1", | 28 | "16 16 78 1", |
@@ -116,37 +121,64 @@ static char * filesave_xpm[] = { | |||
116 | " +...z]n$ ", | 121 | " +...z]n$ ", |
117 | " +... "}; | 122 | " +... "}; |
118 | 123 | ||
119 | Output::Output( QWidget* parent, const char* name, bool modal, WFlags fl ) | 124 | Output::Output( const QStringList commands, QWidget* parent, const char* name, bool modal, WFlags fl) |
120 | : QDialog( parent, name, modal, fl ) | 125 | : QDialog( parent, name, modal, fl ) |
121 | { | 126 | { |
122 | if ( !name ) | 127 | QStringList cmmds; |
123 | setName( "Output" ); | 128 | // cmmds=QStringList::split( " ", commands, false); |
129 | cmmds=commands; | ||
130 | // qDebug("count %d", cmmds.count()); | ||
131 | if ( !name ) | ||
132 | setName( tr("Output")); | ||
124 | resize( 196, 269 ); | 133 | resize( 196, 269 ); |
125 | setCaption( name ); | 134 | setCaption( name ); |
135 | |||
126 | OutputLayout = new QGridLayout( this ); | 136 | OutputLayout = new QGridLayout( this ); |
127 | OutputLayout->setSpacing( 6 ); | 137 | OutputLayout->setSpacing( 2); |
128 | OutputLayout->setMargin( 11 ); | 138 | OutputLayout->setMargin( 2); |
129 | 139 | ||
130 | QPushButton *docButton; | 140 | QPushButton *docButton; |
131 | docButton = new QPushButton( QPixmap(( const char** ) filesave_xpm ) ,"",this,"saveButton"); | 141 | docButton = new QPushButton( QPixmap(( const char** ) filesave_xpm ) ,"",this,"saveButton"); |
132 | docButton->setFixedSize( QSize( 20, 20 ) ); | 142 | docButton->setFixedSize( QSize( 20, 20 ) ); |
133 | connect( docButton,SIGNAL(released()),this,SLOT( saveOutput() )); | 143 | connect( docButton,SIGNAL(released()),this,SLOT( saveOutput() )); |
134 | // docButton->setFlat(TRUE); | 144 | // docButton->setFlat(TRUE); |
135 | OutputLayout->addMultiCellWidget( docButton, 0,0,3,3 ); | 145 | OutputLayout->addMultiCellWidget( docButton, 0,0,3,3 ); |
136 | |||
137 | 146 | ||
138 | OutputEdit = new QMultiLineEdit( this, "OutputEdit" ); | 147 | OutputEdit = new QMultiLineEdit( this, "OutputEdit" ); |
139 | OutputLayout->addMultiCellWidget( OutputEdit, 1,1,0,3 ); | 148 | OutputLayout->addMultiCellWidget( OutputEdit, 1,1,0,3 ); |
140 | 149 | ||
150 | proc = new OProcess(); | ||
151 | |||
152 | connect(proc, SIGNAL(processExited(OProcess *)), | ||
153 | this, SLOT( processFinished())); | ||
154 | |||
155 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), | ||
156 | this, SLOT(commandStdout(OProcess *, char *, int))); | ||
157 | |||
158 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), | ||
159 | this, SLOT(commandStderr(OProcess *, char *, int))); | ||
160 | |||
161 | // connect( , SIGNAL(received(const QByteArray &)), | ||
162 | // this, SLOT(commandStdin(const QByteArray &))); | ||
163 | |||
164 | // * proc << commands.latin1(); | ||
165 | for ( QStringList::Iterator it = cmmds.begin(); it != cmmds.end(); ++it ) { | ||
166 | qDebug( "%s", (*it).latin1() ); | ||
167 | * proc << (*it).latin1(); | ||
168 | } | ||
141 | 169 | ||
170 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) { | ||
171 | |||
172 | OutputEdit->append("Process could not start"); | ||
173 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | ||
174 | perror("Error: "); | ||
175 | QString errorMsg="Error\n"+(QString)strerror(errno); | ||
176 | OutputEdit->append( errorMsg); | ||
177 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | ||
178 | } | ||
142 | } | 179 | } |
143 | 180 | ||
144 | /* | 181 | Output::~Output() { |
145 | * Destroys the object and frees any allocated resources | ||
146 | */ | ||
147 | Output::~Output() | ||
148 | { | ||
149 | // no need to delete child widgets, Qt does it all for us | ||
150 | } | 182 | } |
151 | 183 | ||
152 | void Output::saveOutput() { | 184 | void Output::saveOutput() { |
@@ -175,6 +207,76 @@ void Output::saveOutput() { | |||
175 | } else | 207 | } else |
176 | qWarning("Could not write file"); | 208 | qWarning("Could not write file"); |
177 | f.close(); | 209 | f.close(); |
178 | |||
179 | } | 210 | } |
180 | } | 211 | } |
212 | |||
213 | void Output::commandStdout(OProcess*, char *buffer, int buflen) { | ||
214 | qWarning("received stdout %d bytes", buflen); | ||
215 | |||
216 | // QByteArray data(buflen); | ||
217 | // data.fill(*buffer, buflen); | ||
218 | // for (uint i = 0; i < data.count(); i++ ) { | ||
219 | // printf("%c", buffer[i] ); | ||
220 | // } | ||
221 | // printf("\n"); | ||
222 | |||
223 | QString lineStr = buffer; | ||
224 | lineStr=lineStr.left(lineStr.length()-1); | ||
225 | OutputEdit->append(lineStr); | ||
226 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | ||
227 | } | ||
228 | |||
229 | |||
230 | void Output::commandStdin( const QByteArray &data) { | ||
231 | qWarning("received stdin %d bytes", data.size()); | ||
232 | // recieved data from the io layer goes to sz | ||
233 | proc->writeStdin(data.data(), data.size()); | ||
234 | } | ||
235 | |||
236 | void Output::commandStderr(OProcess*, char *buffer, int buflen) { | ||
237 | qWarning("received stderrt %d bytes", buflen); | ||
238 | |||
239 | QString lineStr = buffer; | ||
240 | // lineStr=lineStr.left(lineStr.length()-1); | ||
241 | OutputEdit->append(lineStr); | ||
242 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | ||
243 | } | ||
244 | |||
245 | void Output::processFinished() { | ||
246 | |||
247 | delete proc; | ||
248 | OutputEdit->append( "\nFinished\n"); | ||
249 | OutputEdit->setCursorPosition( OutputEdit->numLines() + 1,0,FALSE); | ||
250 | // close(); | ||
251 | // disconnect( layer(), SIGNAL(received(const QByteArray &)), | ||
252 | // this, SLOT(commandStdin(const QByteArray &))); | ||
253 | } | ||
254 | |||
255 | //============================== | ||
256 | |||
257 | InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) | ||
258 | : QDialog( parent, name, modal, fl ) | ||
259 | { | ||
260 | if ( !name ) | ||
261 | setName( "InputDialog" ); | ||
262 | resize( 234, 50 ); | ||
263 | setMaximumSize( QSize( 240, 50 ) ); | ||
264 | setCaption( tr(name ) ); | ||
265 | |||
266 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); | ||
267 | LineEdit1->setGeometry( QRect( 10, 10, 216, 22 ) ); | ||
268 | connect(LineEdit1,SIGNAL(returnPressed()),this,SLOT(returned() )); | ||
269 | } | ||
270 | |||
271 | InputDialog::~InputDialog() { | ||
272 | inputText = LineEdit1->text(); | ||
273 | } | ||
274 | |||
275 | void InputDialog::setInputText(const QString &string) { | ||
276 | LineEdit1->setText( string); | ||
277 | } | ||
278 | |||
279 | void InputDialog::returned() { | ||
280 | inputText = LineEdit1->text(); | ||
281 | this->accept(); | ||
282 | } | ||
diff --git a/noncore/apps/advancedfm/output.h b/noncore/apps/advancedfm/output.h index c1e48da..199a684 100644 --- a/noncore/apps/advancedfm/output.h +++ b/noncore/apps/advancedfm/output.h | |||
@@ -11,6 +11,13 @@ | |||
11 | 11 | ||
12 | #include <qvariant.h> | 12 | #include <qvariant.h> |
13 | #include <qdialog.h> | 13 | #include <qdialog.h> |
14 | #include <qcstring.h> | ||
15 | #include <qstringlist.h> | ||
16 | #include <qlineedit.h> | ||
17 | #include <qwhatsthis.h> | ||
18 | |||
19 | #include <opie/oprocess.h> | ||
20 | |||
14 | class QVBoxLayout; | 21 | class QVBoxLayout; |
15 | class QHBoxLayout; | 22 | class QHBoxLayout; |
16 | class QGridLayout; | 23 | class QGridLayout; |
@@ -21,15 +28,38 @@ class Output : public QDialog | |||
21 | Q_OBJECT | 28 | Q_OBJECT |
22 | 29 | ||
23 | public: | 30 | public: |
24 | Output( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); | 31 | Output(const QStringList commands=0, QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); |
25 | ~Output(); | 32 | ~Output(); |
26 | 33 | ||
27 | QMultiLineEdit* OutputEdit; | 34 | QMultiLineEdit* OutputEdit; |
28 | 35 | ||
29 | protected: | 36 | protected: |
30 | QGridLayout* OutputLayout; | 37 | QGridLayout* OutputLayout; |
38 | OProcess *proc; | ||
31 | protected slots: | 39 | protected slots: |
32 | void saveOutput(); | 40 | void saveOutput(); |
41 | void commandStdout(OProcess*, char *, int); | ||
42 | void commandStdin(const QByteArray &); | ||
43 | void commandStderr(OProcess*, char *, int); | ||
44 | void processFinished(); | ||
45 | private: | ||
46 | QString cmmd; | ||
47 | |||
48 | }; | ||
49 | |||
50 | class InputDialog : public QDialog | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | |||
54 | public: | ||
55 | InputDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); | ||
56 | ~InputDialog(); | ||
57 | QString inputText; | ||
58 | QLineEdit* LineEdit1; | ||
59 | void setInputText(const QString &); | ||
60 | private slots: | ||
61 | void returned(); | ||
62 | |||
33 | }; | 63 | }; |
34 | 64 | ||
35 | #endif // OUTPUT_H | 65 | #endif // OUTPUT_H |