File: exec.cpp

package info (click to toggle)
xexec 0.0.3-24
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 64 kB
  • ctags: 29
  • sloc: cpp: 80; makefile: 62
file content (131 lines) | stat: -rw-r--r-- 4,535 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* >>>>>>>>>>>>>>>>>>>>>> Ken's Programming Model 3.0 <<<<<<
   ================================= File Information ======
   --Name------------------------------------------Content--
    FileName                                       exec.cpp
    Project                                    Project exec
    Copyright                    (C) 1997 Kenneth R. Kinder
    License                      GNU General Public License
 
   ========================================== AUTHORS ======
   --Name----------------------------------Source Initials--
    Kenneth R. Kinder                                   KRK

   ====================================== File Object ======
   ---------------------------------------------------------
    To provide the definitions for Project exec. Project
    exec is to provide a form to run a command line, much
    like KDE's existing kexec. This one is more powerful.
    We hope. =)
   
   ========================================= Calandar ======
   --Code Mark/Description------------Date----------Author--
    Project Started                  08-09-1997         KRK
    Runs Programs                    08-09-1997         KRK
    Version 0.0.2 Mark               08-09-1997         KRK
    Made File browser button         08-14-1997         KRK
    Version 0.0.3 Mark               08-14-1997         KRK
*/

//------------------------------------////// Headers //////
#include "exec.h"

//------------------------------------////// Globals //////


//-----------------------////// Function Definitions //////
  /* Sorry, the main function is defined at the bottom of
  the program. */
void Exec::runline()
   {
   ofstream command_file;  
   int useless;
   command_file.open("/tmp/exec.tmp", ios::out);
  
     /* What we're doing here is saving our command
     in a little shell script that will be ran comming
     up here. */

   command_file
     << "#!/bin/sh\n"
     << cline->text();
        /* The fun, object orriented STREAM way of
        doing things!! wooohoooo */

   command_file.close();			// Finish up.
   
   useless = execlp(SHELL, SHELL, "/tmp/exec.tmp", NULL);
      /* Run shell with command line file as script. */
   }

void Exec::browser()
   {
   QString filename = QFileDialog::getOpenFileName();
      /* This activates the file dialog, and lets the
      user pick and choose on what file she wants.
      Then, it puts it in Qt's glorious string class
      QString. WOO HOO!! */
   
   if (!filename.isNull() )
      {
      cline->setText(filename);
      }
   }

Exec::Exec(QWidget *parent, const char *name) : QWidget(parent,name)
   {
   /* Basicly what we're doing here is setting up the
   dialog to run the command line. It's all pretty
   simple. */
   
   // Set basic window size limits/delimits //
      setMinimumSize(360, 60);
      setMaximumSize(360, 60);
   
   // Put in an edit box for command line //
      cline = new QLineEdit(this, "cline");
         cline->setGeometry(5, 5, 350, 25);
         cline->setFont(QFont("Times", 14, QFont::Normal));
         cline->setFocus();
         
         connect (cline, SIGNAL(returnPressed()), this, SLOT(runline()) );
   
   // Ok Button //
      QPushButton *ok = new QPushButton("Ok", this, "ok");
         ok->setGeometry(5, 35, 50, 20);
         ok->setFont(QFont("Times", 14, QFont::Bold));
         
         connect( ok, SIGNAL(clicked()), this, SLOT(runline()) );
   
   // Cancel Button //
      QPushButton *cancel = new QPushButton("Cancel", this, "cancel");
         cancel->setGeometry(60, 35, 50, 20);
         cancel->setFont(QFont("Times", 14, QFont::Normal));
         
         connect( cancel, SIGNAL(clicked()), qApp, SLOT(quit()) );

   // Browse Button //
      QPushButton *browse = new QPushButton("File", this, "browse");
         browse->setGeometry(115, 35, 50, 20);
         browse->setFont(QFont("Times", 14, QFont::Normal));
         
         connect( browse, SIGNAL(clicked()), this, SLOT(browser()) );
   
   }

//------------------------------////// Main Function //////
int main(int argc, char **argv)
	{
    cout << endl << endl << "-= exec =-" << endl
         << "Version " << VERSI0N << " by " << AUTHOR << endl
         << URL << " " << CONTACT << endl << endl
         << "exec is distributed under the terms in the GNU General Public License." << endl << endl;
    
	QApplication a(argc, argv);
       /* Initialize us with Qt/X */
	
    /* Run the program... */
    Exec Window;
    a.setMainWidget(&Window);
    Window.show();
    return a.exec();
    }