Skip to content

Commit

Permalink
Merge pull request #22 from peterkomar/structure
Browse files Browse the repository at this point in the history
Structure
  • Loading branch information
peterkomar committed Dec 23, 2015
2 parents c89388f + b5148d1 commit 389a70e
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 32 deletions.
File renamed without changes.
Binary file not shown.
Binary file added icons/.DS_Store
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 3 additions & 1 deletion desktop/qrestclient.desktop → qrestclient.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ X-KDE-StartupNotify=true
Icon=qrestclient
Terminal=false
Categories=Development;Utilities;
InitialPreference=9
InitialPreference=9
StartupNotify=false
Encoding=UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ make %{?_smp_mflags}
%install
mkdir -p %{buildroot}/usr/bin
mkdir -p %{buildroot}/usr/share/applications
mkdir -p %{buildroot}/usr/share/icons
mkdir -p %{buildroot}/usr/share/icons/hicolor
cp bin/qrestclient %{buildroot}/usr/bin
cp -R desktop/qrestclient.desktop %{buildroot}/usr/share/applications
cp -R -f desktop/icons %{buildroot}/usr/share
cp -R qrestclient.desktop %{buildroot}/usr/share/applications
cp -R -f icons/* %{buildroot}/usr/share/icons/hicolor
%clean
rm -rf $RPM_BUILD_ROOT
%post
Expand Down
17 changes: 14 additions & 3 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
***************************************************************************/
#include "menu.h"
#include "restclientmainwindow.h"
#include "responsewidget.h"

#include <QMenuBar>
#include <QActionGroup>
Expand All @@ -31,25 +32,35 @@ Menu::Menu(RestClientMainWindow* app)
m_jsonView = new QAction("Json", app);
m_textView = new QAction("Text", app);
m_csvView = new QAction("CSV", app);
m_htmlView = new QAction("Html", app);

QActionGroup *viewGroup = new QActionGroup(app);
viewGroup->addAction(m_jsonView);
viewGroup->addAction(m_textView);
viewGroup->addAction(m_csvView);
viewGroup->addAction(m_htmlView);

m_jsonView->setCheckable(true);
m_textView->setCheckable(true);
m_csvView->setCheckable(true);
m_htmlView->setCheckable(true);

m_textView->setChecked(true);

view->addAction(m_jsonView);
view->addAction(m_textView);
view->addAction(m_csvView);
view->addAction(m_htmlView);

QObject::connect(m_jsonView, SIGNAL(triggered()), app, SLOT(slotViewJson()));
QObject::connect(m_textView, SIGNAL(triggered()), app, SLOT(slotViewText()));
QObject::connect(m_csvView, SIGNAL(triggered()), app, SLOT(slotViewCsv()));
m_jsonView->setProperty("type", ResponseWidget::TYPE_JSON);
m_textView->setProperty("type", ResponseWidget::TYPE_TEXT);
m_csvView->setProperty("type", ResponseWidget::TYPE_CSV);
m_htmlView->setProperty("type", ResponseWidget::TYPE_HTML);

QObject::connect(m_jsonView, SIGNAL(triggered()), app, SLOT(slotViewMode()));
QObject::connect(m_textView, SIGNAL(triggered()), app, SLOT(slotViewMode()));
QObject::connect(m_csvView, SIGNAL(triggered()), app, SLOT(slotViewMode()));
QObject::connect(m_htmlView, SIGNAL(triggered()), app, SLOT(slotViewMode()));

QAction *a = new QAction(QObject::tr("About"), app);
QMenu *m = app->menuBar()->addMenu(QObject::tr("Help"));
Expand Down
1 change: 1 addition & 0 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Menu
QAction *m_jsonView;
QAction *m_textView;
QAction *m_csvView;
QAction *m_htmlView;
};

#endif // MENU_H
18 changes: 12 additions & 6 deletions src/responsewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,25 @@
#include "qcsvview.h"

#include <QTextEdit>
#include <QDebug>
#include <QTextBrowser>

ResponseWidget::ResponseWidget(QWidget *parent) :
QStackedWidget(parent)
{
m_textView = new QTextEdit;
m_textView->setReadOnly(true);
addWidget(m_textView);
insertWidget(TYPE_TEXT, m_textView);

m_htmlView = new QTextBrowser;
insertWidget(TYPE_HTML, m_htmlView);

m_jsonView = new QJsonView;
addWidget(m_jsonView);
insertWidget(TYPE_JSON, m_jsonView);

m_csvView = new QCsvView;
addWidget(m_csvView);
insertWidget(TYPE_CSV, m_csvView);

setCurrentIndex(0);
setCurrentIndex(TYPE_TEXT);

m_text = "";
}
Expand Down Expand Up @@ -72,6 +75,9 @@ ResponseWidget::type ResponseWidget::render(type typeResponse)
case TYPE_CSV: index = TYPE_CSV;
m_csvView->setText(body);
break;
case TYPE_HTML: index = TYPE_HTML;
m_htmlView->setHtml(body);
break;

}

Expand All @@ -80,7 +86,7 @@ ResponseWidget::type ResponseWidget::render(type typeResponse)
m_textView->setPlainText(body);
}

setCurrentIndex(index);
setCurrentIndex((int)index);

return index;
}
Expand Down
3 changes: 3 additions & 0 deletions src/responsewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
class QTextEdit;
class QJsonView;
class QCsvView;
class QTextBrowser;

class ResponseWidget : public QStackedWidget
{
Expand All @@ -36,6 +37,7 @@ class ResponseWidget : public QStackedWidget
TYPE_TEXT = 0,
TYPE_JSON,
TYPE_CSV,
TYPE_HTML,
};

explicit ResponseWidget(QWidget *parent = 0);
Expand All @@ -50,6 +52,7 @@ class ResponseWidget : public QStackedWidget
QTextEdit *m_textView;
QJsonView *m_jsonView;
QCsvView *m_csvView;
QTextBrowser *m_htmlView;

QString m_text;
};
Expand Down
28 changes: 12 additions & 16 deletions src/restclientmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,34 +418,30 @@ void RestClientMainWindow::slotHideHistoryFilter()
loadHistory();
}

void RestClientMainWindow::slotViewJson()
void RestClientMainWindow::slotViewMode()
{
ResponseWidget::type type = m_mainPanel->m_response->render(ResponseWidget::TYPE_JSON);
if(QAction *action = qobject_cast<QAction *>(sender())) {
ResponseWidget::type typeOrigin = (ResponseWidget::type)action->property("type").toInt();
ResponseWidget::type type = m_mainPanel->m_response->render(typeOrigin);

if( type != ResponseWidget::TYPE_JSON ) {
QMessageBox::critical(this, tr("Error parese"), tr("Error parsing JSON"));
if (typeOrigin == ResponseWidget::TYPE_JSON && typeOrigin != type) {
QMessageBox::critical(this, tr("Error parese"), tr("Error parsing JSON"));
}
slotNotifyMenuView(type);
}
}

void RestClientMainWindow::slotViewText()
{
ResponseWidget::type type = m_mainPanel->m_response->render(ResponseWidget::TYPE_TEXT);
slotNotifyMenuView(type);
}

void RestClientMainWindow::slotViewCsv()
{
ResponseWidget::type type = m_mainPanel->m_response->render(ResponseWidget::TYPE_CSV);
slotNotifyMenuView(type);
}

void RestClientMainWindow::slotNotifyMenuView(int pos)
{
switch (pos) {
case ResponseWidget::TYPE_TEXT: m_menu->m_textView->setChecked(true);
break;
case ResponseWidget::TYPE_JSON: m_menu->m_jsonView->setChecked(true);
break;
case ResponseWidget::TYPE_CSV: m_menu->m_csvView->setChecked(true);
break;
case ResponseWidget::TYPE_HTML: m_menu->m_htmlView->setChecked(true);
break;
default:
break;
}
Expand Down
5 changes: 2 additions & 3 deletions src/restclientmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ public slots:
void slotHideHistoryFilter();
void slotRequestDetails();

void slotViewJson();
void slotViewText();
void slotViewCsv();
void slotViewMode();

void slotAbout();

void slotNotifyMenuView(int pos);
Expand Down

0 comments on commit 389a70e

Please sign in to comment.