1 /***************************************************************************
2                           rkcommandlog  -  description
3                              -------------------
4     begin                : Sun Nov 3 2002
5     copyright            : (C) 2002, 2004, 2005, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
6     email                : thomas.friedrichsmeier@kdemail.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef RKCOMMANDLOG_H
19 #define RKCOMMANDLOG_H
20 
21 #include <qstring.h>
22 #include <qtextedit.h>
23 
24 #include "rkmdiwindow.h"
25 #include "../settings/rksettings.h"
26 #include "../rbackend/rcommandreceiver.h"
27 
28 class RCommand;
29 struct ROutput;
30 class RKCommandLogView;
31 class RKCommandLogPart;
32 
33 /**
34 	\brief This widget shows all executed commands and their result
35 @author Thomas Friedrichsmeier
36 */
37 
38 class RKCommandLog : public RKMDIWindow, public RCommandReceiver {
39 	Q_OBJECT
40 public:
41 /** Adds input to the log_view-window (i.e. commands issued) */
42 	void addInput (RCommand *command);
43 /** Adds output to the log_view-window (i.e. replies received) */
44 	void newOutput (RCommand *command, ROutput *output_fragment) override;
45 
getLog()46 	static RKCommandLog *getLog () { return rkcommand_log; };
47 
getView()48 	RKCommandLogView *getView () { return log_view; };
49 protected:
50 /** Command has finished. If the command has failed, it may be necessary to print some more information */
51 	void rCommandDone (RCommand *command) override;
52 	RKCommandLog (QWidget *parent, bool tool_window, const char *name=0);
53 	~RKCommandLog ();
54 public slots:
55 /** configures the log_view-window */
56 	void configureLog ();
57 /** clears the log_view-window */
58 	void clearLog ();
59 	void runSelection ();
60 	void settingsChanged (RKSettings::SettingsPage page);
61 private:
62 	void addInputNoCheck (RCommand *command);
63 	void addOutputNoCheck (RCommand *command, ROutput *output);
64 	void checkRaiseWindow (RCommand *command);
65 /** internal helper function, called whenever a line/lines have been added. Check whether log is longer than maximum setting. Scroll to the bottom */
66 	void linesAdded ();
67 /** Used to keep track, which commands "input" has already been shown */
68 	QList<RCommand*> command_input_shown;
69 /** On a given command, the log_view should not be raised more than once */
70 	int last_raised_command;
71 
72 	RKCommandLogView *log_view;
73 friend class RKWardMainWindow;
74 	static RKCommandLog *rkcommand_log;
75 };
76 
77 /** Simply subclass of QTextEdit to override context menu handling */
78 class RKCommandLogView : public QTextEdit {
79 	Q_OBJECT
80 public:
81 	explicit RKCommandLogView (RKCommandLog *parent);
82 	~RKCommandLogView ();
83 public slots:
84 	void selectAll ();
85 signals:
86 	void popupMenuRequest (const QPoint &pos);
87 protected:
88 	void contextMenuEvent (QContextMenuEvent *event) override;
89 };
90 
91 #include <kparts/part.h>
92 
93 class QAction;
94 
95 /** Provides a part interface for the RKCommandLog */
96 class RKCommandLogPart : public KParts::Part {
97 	Q_OBJECT
98 public:
99 	explicit RKCommandLogPart (RKCommandLog *for_log);
100 	~RKCommandLogPart ();
101 
102 	void initActions ();
103 public slots:
104 	void doPopupMenu (const QPoint &pos);
105 private:
106 	RKCommandLog *log;
107 
108 	QAction *run_selection;
109 	QAction *copy;
110 };
111 
112 #endif
113