[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [plasmate/terietor/konsolepreviewer] /: populate the konsole previewer
From: Giorgos Tsiapaliwkas <terietor () gmail ! com>
Date: 2012-07-10 15:23:30
Message-ID: 20120710152330.A6C85A6094 () git ! kde ! org
[Download RAW message or body]
Git commit 80f9716831866c3cfd8aec169ac520513ee758d0 by Giorgos Tsiapaliwkas.
Committed on 10/07/2012 at 17:17.
Pushed by tsiapaliwkas into branch 'terietor/konsolepreviewer'.
populate the konsole previewer
M +1 -0 CMakeLists.txt
A +73 -0 konsole/konsolepreviewer.cpp [License: GPL (v2+)]
C +15 -15 konsole/konsolepreviewer.h [from: \
previewer/plasmoid/plasmoidpreviewer.h - 060% similarity] M +31 -0 main.cpp
M +27 -1 mainwindow.cpp
M +4 -1 mainwindow.h
M +11 -0 previewer/plasmoid/plasmoidpreviewer.cpp
M +1 -0 previewer/plasmoid/plasmoidpreviewer.h
M +1 -0 previewer/plasmoid/plasmoidview.cpp
M +7 -0 previewer/plasmoid/previewcontainment.cpp
M +1 -0 previewer/plasmoid/previewcontainment.h
M +6 -1 previewer/previewer.cpp
M +13 -0 previewer/previewer.h
M +7 -1 previewer/runner/runnerpreviewer.cpp
M +1 -0 previewer/runner/runnerpreviewer.h
http://commits.kde.org/plasmate/80f9716831866c3cfd8aec169ac520513ee758d0
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 12f8a3a..18d91ba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -54,6 +54,7 @@ set (PlasMate_SRC
publisher/signingwidget.cpp
publisher/signingdialog.cpp
publisher/publisher.cpp
+ konsole/konsolepreviewer.cpp
docbrowser/docbrowser.cpp
projectmanager/projectmanager.cpp
)
diff --git a/konsole/konsolepreviewer.cpp b/konsole/konsolepreviewer.cpp
new file mode 100644
index 0000000..cd6e6ed
--- /dev/null
+++ b/konsole/konsolepreviewer.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2012 Giorgos Tsiapaliwkas <terietor@gmail.com>
+ *
+ * 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.
+ *
+ */
+
+#include "konsolepreviewer.h"
+
+#include <QVBoxLayout>
+#include <QFile>
+#include <KAction>
+#include <KFileDialog>
+#include <KMessageBox>
+#include <KStandardAction>
+#include <KTextEdit>
+#include <KToolBar>
+#include <KUrl>
+#include <KUser>
+#include <KIO/CopyJob>
+
+KonsolePreviewer::KonsolePreviewer(const QString & title, QWidget *parent)
+ : QDockWidget(title, parent),
+ m_textEdit(0)
+{
+ QVBoxLayout *layout = new QVBoxLayout();
+ KToolBar *toolBar = new KToolBar(this, true, true);
+ toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+
+ KAction *clear = KStandardAction::clear(this, SLOT(clearOutput()), this);
+ KAction *save = KStandardAction::save(this, SLOT(saveOutput()), this);
+ toolBar->addAction(clear);
+ toolBar->addAction(save);
+
+ m_textEdit = new KTextEdit();
+
+ layout->addWidget(toolBar);
+ layout->addWidget(m_textEdit);
+
+ QWidget *tmpWidget = new QWidget(this);
+ tmpWidget->setLayout(layout);
+ setWidget(tmpWidget);
+}
+
+void KonsolePreviewer::clearOutput()
+{
+ m_textEdit->clear();
+}
+
+void KonsolePreviewer::setOutput(const QString& output)
+{
+ m_textEdit->setText(output);
+
+}
+
+void KonsolePreviewer::saveOutput()
+{
+ //m_fileDialog = new KFileDialog(KUrl(), QString(), 0);
+ //m_fileDialog->setOperationMode(KFileDialog::Saving);
+ //m_fileDialog->setCaption("Save Script File");
+ KUser user;
+ KUrl destination = KFileDialog::getSaveUrl(KUrl(user.homeDir()), ".*", this);
+
+ if (destination.isEmpty()) {
+ return;
+ }
+
+ KIO::copy(KUrl("/var/tmp/plasmatepreviewerlog.txt"), destination, \
KIO::Overwrite); +}
+
diff --git a/previewer/plasmoid/plasmoidpreviewer.h b/konsole/konsolepreviewer.h
similarity index 60%
copy from previewer/plasmoid/plasmoidpreviewer.h
copy to konsole/konsolepreviewer.h
index 9cad9e4..d7afd05 100644
--- a/previewer/plasmoid/plasmoidpreviewer.h
+++ b/konsole/konsolepreviewer.h
@@ -1,6 +1,5 @@
/*
- * Copyright 2010 Lim Yuen Hoe <yuenhoe@hotmail.com>
- *
+ * Copyright 2012 Giorgos Tsiapaliwkas <terietor@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@@ -18,26 +17,27 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef PLASMOIDPREVIEWER_H
-#define PLASMOIDPREVIEWER_H
+#ifndef KONSOLEPREVIEWER_H
+#define KONSOLEPREVIEWER_H
-#include "../previewer.h"
-#include "plasmoidview.h"
+#include <QDockWidget>
-class PlasmoidPreviewer : public Previewer {
+class KTextEdit;
- Q_OBJECT
+class KonsolePreviewer : public QDockWidget {
-signals:
- void refreshView(); // emitted to signal the containment to refresh
+ Q_OBJECT
public:
- PlasmoidPreviewer(const QString & title, QWidget * parent = 0, Qt::WindowFlags \
flags = 0 );
- void showPreview(const QString &packagePath);
- void refreshPreview();
+ KonsolePreviewer(const QString & title, QWidget *parent = 0);
+
+public Q_SLOTS:
+ void clearOutput();
+ void setOutput(const QString& output);
+ void saveOutput();
private:
- PlasmoidView* m_view;
+ KTextEdit *m_textEdit;
};
-#endif // PLASMOIDPREVIEWER_H
\ No newline at end of file
+#endif // KONSOLEPREVIEWER_H
diff --git a/main.cpp b/main.cpp
index 1c5ea19..e986417 100644
--- a/main.cpp
+++ b/main.cpp
@@ -15,15 +15,46 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <iostream>
+
#include <KApplication>
#include <KAboutData>
#include <KLocale>
#include <KCmdLineArgs>
+#include <QFile>
+#include <QTextStream>
+
#include "mainwindow.h"
+void customMessageHandler(QtMsgType type, const char *msg)
+{
+ QString txt;
+ switch (type) {
+ case QtDebugMsg:
+ txt = QString("Debug: %1").arg(msg);
+ break;
+ case QtWarningMsg:
+ txt = QString("Warning: %1").arg(msg);
+ break;
+ case QtCriticalMsg:
+ txt = QString("Critical: %1").arg(msg);
+ break;
+ case QtFatalMsg:
+ txt = QString("Fatal: %1").arg(msg);
+ abort();
+ }
+ QFile outFile("/var/tmp/plasmatepreviewerlog.txt");
+ outFile.open(QIODevice::WriteOnly | QIODevice::Append);
+ QTextStream ts(&outFile);
+ ts << txt << endl;
+ std::cout << txt.toLocal8Bit().constData() << std::endl;
+}
+
int main(int argc, char *argv[])
{
+ qInstallMsgHandler(customMessageHandler);
+
KAboutData aboutData("plasmate", 0, ki18n("Plasmate"),
"0.1alpha3", ki18n("Plasma Add-Ons Creator"),
KAboutData::License_GPL,
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 6f72624..a864f30 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -55,6 +55,7 @@ along with this program. If not, see \
<http://www.gnu.org/licenses/>. #include "packagemodel.h"
#include "sidebar.h"
#include "startpage.h"
+#include "konsole/konsolepreviewer.h"
#include "previewer/plasmoid/plasmoidpreviewer.h"
#include "previewer/runner/runnerpreviewer.h"
#include "publisher/publisher.h"
@@ -609,7 +610,6 @@ void MainWindow::updateSideBar()
m_oldTab = EditTab;
}
-
void MainWindow::loadImageViewer(const KUrl& target)
{
saveEditorData();
@@ -623,6 +623,21 @@ void MainWindow::loadImageViewer(const KUrl& target)
updateSideBar();
}
+void MainWindow::showKonsolePreviewer()
+{
+ if(m_konsole->isVisible()) {
+ m_konsole->setVisible(false);
+ } else {
+ m_konsole->setVisible(true);
+ }
+}
+
+void MainWindow::reloadKonsolePreviewer()
+{
+ if (m_konsole && m_previewerWidget) {
+ m_konsole->setOutput(m_previewerWidget->takeOutput());
+ }
+}
void MainWindow::loadMetaDataEditor(KUrl target)
{
@@ -754,6 +769,10 @@ void MainWindow::loadProject(const QString &path)
refreshNotes();
}
+
+ //initialize the konsole previewer
+ m_konsole = new KonsolePreviewer(i18n("Previewer Output"), this);
+
// initialize previewer
delete m_previewerWidget;
m_previewerWidget = createPreviewerFor(actualType);
@@ -762,6 +781,12 @@ void MainWindow::loadProject(const QString &path)
addDockWidget(Qt::LeftDockWidgetArea, m_previewerWidget);
m_previewerWidget->showPreview(packagePath);
m_previewerWidget->setVisible(showPreview);
+
+ //now do the relative stuff for the konsole
+ m_konsole->setOutput(m_previewerWidget->takeOutput());
+ m_konsole->setObjectName("Previewer Output");
+ connect(m_previewerWidget, SIGNAL(showKonsole()), this, \
SLOT(showKonsolePreviewer())); + addDockWidget(Qt::BottomDockWidgetArea, \
m_konsole); }
restoreState(state, STATE_VERSION);
@@ -877,6 +902,7 @@ Previewer* MainWindow::createPreviewerFor(const QString& \
projectType) if (ret) {
ret->setObjectName("preview");
connect(ret, SIGNAL(refreshRequested()), this, SLOT(saveAndRefresh()));
+ connect(ret, SIGNAL(refreshRequested()), this, \
SLOT(reloadKonsolePreviewer()));
connect(ret, SIGNAL(visibilityChanged(bool)), this, SLOT(updateActions()));
}
diff --git a/mainwindow.h b/mainwindow.h
index 520c26c..d187296 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -44,6 +44,7 @@ class TimeLine;
class MetaDataEditor;
class ImageViewer;
class TextEditor;
+class KonsolePreviewer;
// our own previewer
class Previewer;
@@ -107,6 +108,8 @@ private Q_SLOTS:
void toggleNotes();
void toggleFileList();
void installPackage();
+ void showKonsolePreviewer();
+ void reloadKonsolePreviewer();
// refreshes editor, killing all local changes
void editorDestructiveRefresh();
@@ -156,7 +159,7 @@ private:
Publisher *m_publisher;
DocBrowser *m_browser;
TextEditor *m_textEditor;
-
+ KonsolePreviewer *m_konsole;
QDockWidget *m_filelist;
EditPage *m_editPage;
diff --git a/previewer/plasmoid/plasmoidpreviewer.cpp \
b/previewer/plasmoid/plasmoidpreviewer.cpp index 29853db..478b498 100644
--- a/previewer/plasmoid/plasmoidpreviewer.cpp
+++ b/previewer/plasmoid/plasmoidpreviewer.cpp
@@ -10,6 +10,8 @@
#include "plasmoidpreviewer.h"
+#include <QFile>
+
PlasmoidPreviewer::PlasmoidPreviewer(const QString & title, QWidget * parent, \
Qt::WindowFlags flags) : Previewer(title, parent, flags)
{
@@ -27,3 +29,12 @@ void PlasmoidPreviewer::refreshPreview()
emit refreshView();
}
+QString PlasmoidPreviewer::takeOutput() const
+{
+ QFile file("/var/tmp/plasmatepreviewerlog.txt");
+ if (file.open(QIODevice::ReadOnly)) {
+ return file.readAll();
+ }
+
+ return QString();
+}
diff --git a/previewer/plasmoid/plasmoidpreviewer.h \
b/previewer/plasmoid/plasmoidpreviewer.h index 9cad9e4..2a247dd 100644
--- a/previewer/plasmoid/plasmoidpreviewer.h
+++ b/previewer/plasmoid/plasmoidpreviewer.h
@@ -35,6 +35,7 @@ public:
PlasmoidPreviewer(const QString & title, QWidget * parent = 0, Qt::WindowFlags \
flags = 0 ); void showPreview(const QString &packagePath);
void refreshPreview();
+ QString takeOutput() const;
private:
PlasmoidView* m_view;
diff --git a/previewer/plasmoid/plasmoidview.cpp \
b/previewer/plasmoid/plasmoidview.cpp index 3d40d48..7a50e02 100644
--- a/previewer/plasmoid/plasmoidview.cpp
+++ b/previewer/plasmoid/plasmoidview.cpp
@@ -54,6 +54,7 @@ PlasmoidView::PlasmoidView(QWidget *parent)
// we do a two-way connect here to allow the previewer containment
// and main window to tell each other to save/refresh
connect(m_containment, SIGNAL(refreshClicked()), parent, \
SLOT(emitRefreshRequest())); + connect(m_containment, SIGNAL(showKonsole()), \
parent, SLOT(emitShowKonsole()));
connect(parent, SIGNAL(refreshView()), m_containment, SLOT(refreshApplet()));
setScene(&m_corona);
diff --git a/previewer/plasmoid/previewcontainment.cpp \
b/previewer/plasmoid/previewcontainment.cpp index 42b6af7..c081294 100644
--- a/previewer/plasmoid/previewcontainment.cpp
+++ b/previewer/plasmoid/previewcontainment.cpp
@@ -27,6 +27,7 @@
#include <QGraphicsLayoutItem>
#include <KAction>
+#include <KConfigGroup>
#include <KIcon>
#include <KMenu>
@@ -84,6 +85,7 @@ void PreviewContainment::setupHeader()
Plasma::IconWidget *refresh = new Plasma::IconWidget(this);
Plasma::IconWidget *location = new Plasma::IconWidget(this);
Plasma::IconWidget *wallpaper = new Plasma::IconWidget(this);
+ Plasma::IconWidget *konsole = new Plasma::IconWidget(this);
// add actions
KAction *action0 = new KAction(KIcon("user-desktop"), "", this);
@@ -102,11 +104,16 @@ void PreviewContainment::setupHeader()
connect(action3, SIGNAL(triggered()), this, SLOT(refreshAndEmit()));
refresh->setAction(action3);
+ KAction *action4 = new KAction(KIcon("konsole"), "", this);
+ connect(action4, SIGNAL(triggered()), this, SIGNAL(showKonsole()));
+ konsole->setAction(action4);
+
// add the toolboxes
m_header->addItem(refresh);
m_header->addItem(form);
m_header->addItem(location);
m_header->addItem(wallpaper);
+ m_header->addItem(konsole);
}
// Fixme(?): Does not currently respect arguments passed in during
diff --git a/previewer/plasmoid/previewcontainment.h \
b/previewer/plasmoid/previewcontainment.h index fb10941..34dfb52 100644
--- a/previewer/plasmoid/previewcontainment.h
+++ b/previewer/plasmoid/previewcontainment.h
@@ -47,6 +47,7 @@ public slots:
signals:
void refreshClicked();
+ void showKonsole();
protected slots:
void refreshAndEmit();
diff --git a/previewer/previewer.cpp b/previewer/previewer.cpp
index c9d7479..0521cfc 100644
--- a/previewer/previewer.cpp
+++ b/previewer/previewer.cpp
@@ -30,4 +30,9 @@ Previewer::Previewer(QWidget * parent, Qt::WindowFlags flags)
void Previewer::emitRefreshRequest()
{
emit refreshRequested();
-}
\ No newline at end of file
+}
+
+void Previewer::emitShowKonsole()
+{
+ emit showKonsole();
+}
diff --git a/previewer/previewer.h b/previewer/previewer.h
index 2907598..3712b61 100644
--- a/previewer/previewer.h
+++ b/previewer/previewer.h
@@ -29,6 +29,7 @@ class Previewer : public QDockWidget {
signals:
void refreshRequested();
+ void showKonsole();
public:
Previewer(const QString & title, QWidget * parent = 0, Qt::WindowFlags flags = 0 \
); @@ -37,6 +38,13 @@ public:
* Subclasses should override this method with actual previewing code
*/
virtual void showPreview(const QString &packagePath) = 0;
+
+ /**
+ * Subclasses should override this method with the actual code which
+ * will take the output
+ **/
+ virtual QString takeOutput() const = 0;
+
/**
* Subclasses should override this method with code that refreshes the preview
*/
@@ -50,6 +58,11 @@ public slots:
*/
void emitRefreshRequest();
+ /**
+ * Emits showKonsole(), which will show the konsole. All subclasses should \
call/connect + * to this when the user requests a to see the konsole.
+ **/
+ virtual void emitShowKonsole();
};
#endif // PREVIEWER_H
\ No newline at end of file
diff --git a/previewer/runner/runnerpreviewer.cpp \
b/previewer/runner/runnerpreviewer.cpp index 5c8dc6d..c1c5b47 100644
--- a/previewer/runner/runnerpreviewer.cpp
+++ b/previewer/runner/runnerpreviewer.cpp
@@ -77,4 +77,10 @@ void RunnerPreviewer::doQuery()
if (m_runner) {
m_runner->launchQuery(m_edit->text());
}
-}
\ No newline at end of file
+}
+
+QString RunnerPreviewer::takeOutput() const
+{
+ //TODO add support for a runner previewer
+ return QString();
+}
diff --git a/previewer/runner/runnerpreviewer.h b/previewer/runner/runnerpreviewer.h
index 054c58d..2ac687e 100644
--- a/previewer/runner/runnerpreviewer.h
+++ b/previewer/runner/runnerpreviewer.h
@@ -30,6 +30,7 @@ public:
~RunnerPreviewer();
void showPreview(const QString &packagePath);
void refreshPreview();
+ QString takeOutput() const;
public slots:
void doQuery();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic