summaryrefslogtreecommitdiff
path: root/src/fqterm/fqterm_window.h
blob: 377af4fb6291116f864b216fa2320518842784d3 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/***************************************************************************
 *   fqterm, a terminal emulator for both BBS and *nix.                    *
 *   Copyright (C) 2008 fqterm development group.                          *
 *                                                                         *
 *   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.,                                       *
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.               *
 ***************************************************************************/

#ifndef FQTERM_WINDOW_H
#define FQTERM_WINDOW_H

#include <QMainWindow>
#include <QCursor>
#include <QString>
#include <QProcess>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "fqterm_param.h"
#include "fqterm_config.h"
#include "fqterm_convert.h"
#include "fqterm_session.h"

class QCloseEvent;
class QEvent;
class QKeyEvent;
class QMouseEvent;
class QMouseEvent; 
class QProgressBar;
class QWheelEvent;

namespace FQTerm {

//class QProgressDialog;
class PageViewMessage;
class FQTermConfig;
class FQTermImage;
class FQTermFrame;
class FQTermHttp;
class FQTermScreen;
class FQTermSession;
class FQTermSound;
class FQTermWindow;
class popWidget;
class zmodemDialog;
class FQTermScriptEngine;

class FQTermExternalEditor : public QObject {
  Q_OBJECT;
public:
  FQTermExternalEditor(QWidget* parent);
  ~FQTermExternalEditor();
  void start();
signals:
  void done(const QString&);
public slots:
  void stateChanged(QProcess::ProcessState state);
protected slots:
  void readDialogData();
  void closeDialog();
private:
  void execDialog();
  QString getTempFilename();
  void clearTempFileContent();
  
  static const QString textEditName_;
  bool started_;
  QProcess* editorProcess_;
};

class FQTermWindow : public QMainWindow,
                      public FQTermScriptEventListener {
  friend class FQTermScreen;

  Q_OBJECT;
 public:
  FQTermWindow(FQTermConfig *, FQTermFrame *frame, FQTermParam param, int addr = -1, QWidget
              *parent = 0, const char *name = 0, Qt::WindowFlags wflags = Qt::Window);
  ~FQTermWindow();

  void connectHost();
  bool isConnected();

  void disconnect();
  //redraw the dirty lines
  void refreshScreen();
  //repaint a dirty rectangle.
  void repaintScreen();
  //force a repaint by sending a resize event
  void forcedRepaintScreen();
  void viewMessages();
  void toggleAutoReply();
  void toggleAntiIdle();
  void toggleAutoReconnect();
  void setFont(bool isEnglish);
  void saveSetting(bool ask = true);

  void runScript(const QString & filename);
  int externInput(const QByteArray &);
  int externInput(const QString &);
  void getHttpHelper(const QString &, bool);

  void openUrl(QString url);
  void openUrlImpl(QString url);

  FQTermSession * getSession() const { return session_; }
  FQTermScreen * getScreen() const {return screen_;}
  FQTermConfig * getConfig() const { return config_; }
        
  QPoint getUrlStartPoint() const { return urlStartPoint_; }
  QPoint getUrlEndPoint() const { return urlEndPoint_; }

  //FQTermScriptEventListener
private:
  virtual bool postQtScriptCallback(const QString& func, const QScriptValueList & args = QScriptValueList());
#ifdef HAVE_PYTHON
  virtual bool postPythonCallback(const QString& func, PyObject* pArgs);
#endif //HAVE_PYTHON

public:
  virtual long windowID() {return long(this);}
  //end FQTermScriptEventListener

signals:
  void resizeSignal(FQTermWindow*);
  void refreshOthers(FQTermWindow*);
  void blinkTheTab(FQTermWindow*, bool);
  void connectionClosed(FQTermWindow*);
 public slots:
  // ui
  void copy();
  void paste();
  void openAsUrl();
  void searchIt();
  void shareIt();
  void externalEditor();
  void fastPost();
  void copyArticle();
  void setting();
  void setColor();
  void runScript();
  void stopScript();
  
  void sendParsedString(const char*);
  void showIP(bool show = true);

  void beep();
  void startBlink();
  void stopBlink();
  void onTitleSet(const QString& title);

  void connectionClosed();

  void messageAutoReplied();

  void pasteHelper(bool);

  QByteArray parseString(const QByteArray &, int *len = 0);

  //  void sendMouseState(int, Qt::KeyboardModifier, Qt::KeyboardModifier, const
  //                    QPoint &);


 protected slots:
  void setFont();
  void recreateMenu();
  
  //refresh screen & reset cursor position
  void sessionUpdated();

  void requestUserPwd(QString *userName, QString *password, bool *isOK);
  void warnInsecure(const QString &msg, bool *isOK);

  void TelnetState(int);
  void ZmodemState(int, int, const char *);
  void showSessionErrorMessage(QString);

  void blinkTab();

  void externalEditorDone(const QString& str);

  //http menu
  void previewLink();
  void saveLink();
  void openLink();
  void copyLink();
  void previewImage(const QString &filename, bool raiseViewer);
  void httpPreviewImage(const QString &filename, bool raiseViewer, bool done);
  void startHttpDownload(FQTermHttp *, const QString &filedesp);

  void httpDone(QObject*);
 
  // decode
  // void setMouseMode(bool);
  void articleCopied(int e, const QString content);


 protected:
  bool event(QEvent*);

  void resizeEvent(QResizeEvent *);
  void mouseDoubleClickEvent(QMouseEvent*);
  void mouseMoveEvent(QMouseEvent*);
  void mousePressEvent(QMouseEvent*);
  void mouseReleaseEvent(QMouseEvent*);
  void wheelEvent(QWheelEvent*);
  void enterEvent(QEvent*);
  void leaveEvent(QEvent*);
  void changeEvent(QEvent*);
  void closeEvent(QCloseEvent*);
  void keyPressEvent(QKeyEvent*);
  //void focusInEvent (QFocusEvent *);

 private:
  FQTermFrame *frame_;
  FQTermScreen *screen_;
  FQTermSession *session_;
  QString allMessages_;
  // before calling repaintScreen(), pls
  // fill this rectangle.
  QRect clientRect_;
  QPoint urlEndPoint_;
  QPoint urlStartPoint_;

  QMenu *menu_;
  QMenu *urlMenu_;

  static char directions_[][5];
  QCursor cursors_[9];

  FQTermConvert encodingConverter_;

  // mouse select
  QPoint lastMouseCell_;
  bool isSelecting_;

  // address setting
  int addressIndex_;

  // url rect
  QRect urlRectangle_;

  //ip rect
  QRect ipRectangle_;
 
  // play sound
  FQTermSound *sound_;


  FQTermConfig *config_;
  zmodemDialog *zmodemDialog_;

  //osd
  PageViewMessage *pageViewMessage_;

  popWidget *popWindow_;
  QTimer *tabBlinkTimer_;

  bool isMouseClicked_;
  bool blinkStatus_;

  bool isUrlUnderLined_;

  FQTermScriptEngine *script_engine_;  
  FQTermExternalEditor *externalEditor_;
 private:
  void addMenu();

  void setCursorPosition(const QPoint& mousePosition);
  //set cursor type according to the content
  //show ip location info if openUrlCheck is set
  void setCursorType(const QPoint& mousePosition);


  void enterMenuItem();
  void processLClick(const QPoint& cellClicked);

  void startSelecting(const QPoint& mousePosition);
  void onSelecting(const QPoint& mousePosition);
  void finishSelecting(const QPoint& mousePosition);

  void updateSetting(const FQTermParam& param);

  void sendKey(const int key, const Qt::KeyboardModifiers modifier,
               const QString &text);

  bool scriptKeyEvent(QKeyEvent *keyevent);
  bool scriptMouseEvent(QMouseEvent *mouseevent);
  bool scriptWheelEvent(QWheelEvent *wheelevent);

  void writePasting(const QString& content);


signals: 
  //these 2 signals are connected to corresponding slots to 
  //make write thread safe.
  int writeStringSignal(const QString& str);
  int writeRawStringSignal(const QString& str);
public slots:
  //for script
  int writeString(const QString& str) {return externInput(str);}
  int writeRawString(const QString& str);
public:
  void writeString_ts(const QString& str) {emit writeStringSignal(str);}
  void writeRawString_ts(const QString& str) {emit writeRawStringSignal(str);}


    
//python support
#ifdef HAVE_PYTHON
public:
  QString getPythonErrorMessage() {
    return pythonErrorMessage_;
  }
  void runPythonScript();
  void runPythonScriptFile(const QString&);
  
protected:
	bool pythonCallback(const QString &, PyObject*);
	int runPythonFile(const QString& file);
  void initPython(const QString& file);
  void finalizePython();
  //void sendMouseState(int, ButtonState, ButtonState, const QPoint&);
private:
	PyObject *pModule, *pDict;
  bool pythonScriptLoaded_;
  QString pythonErrorMessage_;
#endif

};

}  // namespace FQTerm

#endif  // FQTERM_WINDOW_H