Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
huggleweb.cpp
1 //This program is free software: you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation, either version 3 of the License, or
4 //(at your option) any later version.
5 
6 //This program is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
10 
11 #include "huggleweb.hpp"
12 #include "ui_huggleweb.h"
13 
14 using namespace Huggle;
15 
16 HuggleWeb::HuggleWeb(QWidget *parent) : QFrame(parent), ui(new Ui::HuggleWeb)
17 {
18  ui->setupUi(this);
19  /// \todo LOCALIZE ME
20  CurrentPage = "No page is displayed now";
21 }
22 
23 HuggleWeb::~HuggleWeb()
24 {
25  delete ui;
26 }
27 
28 QString HuggleWeb::CurrentPageName()
29 {
30  return CurrentPage;
31 }
32 
34 {
35  if (page == NULL)
36  {
37  throw new Exception("WikiPage *page must not be NULL", "void HuggleWeb::DisplayPreFormattedPage(WikiPage *page)");
38  }
39  ui->webView->history()->clear();
40  ui->webView->load(Core::GetProjectScriptURL() + "index.php?title=" + page->PageName + "&action=render");
41  CurrentPage = page->PageName;
42 }
43 
45 {
46  ui->webView->history()->clear();
47  ui->webView->load(url + "&action=render");
48  CurrentPage = ui->webView->title();
49 }
50 
51 void HuggleWeb::DisplayPage(QString url)
52 {
53  ui->webView->load(url);
54 }
55 
56 void HuggleWeb::RenderHtml(QString html)
57 {
58  ui->webView->setContent(html.toUtf8());
59 }
60 
61 QString HuggleWeb::Encode(const QString &string)
62 {
63  QString encoded;
64  for(int i=0;i<string.size();++i)
65  {
66  QChar ch = string.at(i);
67  if(ch.unicode() > 255)
68  {
69  encoded += QString("&#%1;").arg((int)ch.unicode());
70  }
71  else
72  {
73  encoded += ch;
74  }
75  }
76  encoded = encoded.replace("<", "&lt;");
77  encoded = encoded.replace(">", "&gt;");
78  return encoded;
79 }
80 
82 {
83  ui->webView->history()->clear();
84  if (edit == NULL)
85  {
86  throw new Exception("The page of edit was NULL in HuggleWeb::DisplayDiff(*edit)");
87  }
88  if (edit->Page == NULL)
89  {
90  throw new Exception("The page of edit was NULL in HuggleWeb::DisplayDiff(*edit)");
91  }
92  if (edit->DiffText == "")
93  {
94  Core::Log("Warning, unable to retrieve diff for edit " + edit->Page->PageName + " fallback to web rendering");
95  ui->webView->load(Core::GetProjectScriptURL() + "index.php?title=" + edit->Page->PageName + "&diff="
96  + QString::number(edit->Diff) + "&action=render");
97  return;
98  }
99 
100  QString Summary;
101 
102  QString size;
103 
104  if (edit->Size > 0)
105  {
106  size = "+" + QString::number(edit->Size);
107  } else
108  {
109  size = QString::number(edit->Size);
110  }
111 
112  if (edit->Summary == "")
113  {
114  /// \todo LOCALIZE ME
115  Summary = "<font color=red>No summary was provided</font>";
116  } else
117  {
118  Summary = Encode(edit->Summary);
119  }
120 
121  Summary += "<b> Size change: " + size + "</b>";
122 
123  ui->webView->setHtml(Core::HtmlHeader + "<tr></td colspan=2><b>Summary:</b> "
124  + Summary + "</td></tr>" + edit->DiffText
125  + Core::HtmlFooter);
126 }
static QString GetProjectScriptURL()
Return a script url like http://en.wikipedia.org/w/.
Definition: core.cpp:674
Web browser.
Definition: huggleweb.hpp:31
static void Log(QString Message)
Write text to terminal as well as ring log.
Definition: core.cpp:563
static QString HtmlHeader
This string contains a html header.
Definition: core.hpp:115
HuggleWeb(QWidget *parent=0)
Definition: huggleweb.cpp:16
static QString HtmlFooter
This string contains a html footer.
Definition: core.hpp:117
void DisplayPreFormattedPage(WikiPage *page)
Retrieve a page in render mode on currently selected project.
Definition: huggleweb.cpp:33
Mediawiki page.
Definition: wikipage.hpp:43
QString Summary
Summary of edit.
Definition: wikiedit.hpp:110
Every exception raised by huggle is defined by this class.
Definition: exception.hpp:20
int Diff
Diff id.
Definition: wikiedit.hpp:99
int Size
Size of change of edit.
Definition: wikiedit.hpp:97
Wiki edit.
Definition: wikiedit.hpp:67
void DisplayDiff(WikiEdit *edit)
Definition: huggleweb.cpp:81
void RenderHtml(QString html)
Definition: huggleweb.cpp:56
QString PageName
Name of page.
Definition: wikipage.hpp:48
WikiPage * Page
Page that was changed by edit.
Definition: wikiedit.hpp:87