PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/retroshare-gui/src/gui/GetStartedDialog.cpp

https://gitlab.com/g10h4ck/RetroShare
C++ | 457 lines | 344 code | 71 blank | 42 comment | 16 complexity | 9d26b4544a3f8aca64982c06bb8fcb74 MD5 | raw file
Possible License(s): 0BSD, GPL-2.0, AGPL-1.0
  1. /****************************************************************
  2. * RetroShare is distributed under the following license:
  3. *
  4. * Copyright (C) 2011, drbob
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. ****************************************************************/
  21. #include "gui/GetStartedDialog.h"
  22. #include "gui/connect/ConnectFriendWizard.h"
  23. #include "retroshare/rspeers.h"
  24. #include "retroshare/rsdisc.h"
  25. #include "retroshare/rsconfig.h"
  26. #include "retroshare-gui/RsAutoUpdatePage.h"
  27. #include "rshare.h"
  28. #include <QDesktopServices>
  29. #include <iostream>
  30. #define URL_FAQ "http://retroshare.sourceforge.net/wiki/index.php/Frequently_Asked_Questions"
  31. #define URL_FORUM "http://retroshare.sourceforge.net/forum/"
  32. #define URL_WEBSITE "http://retroshare.org"
  33. #define URL_DOWNLOAD "http://retroshare.sourceforge.net/downloads.html"
  34. #define EMAIL_SUBSCRIBE "lists@retroshare.org"
  35. /** Constructor */
  36. GetStartedDialog::GetStartedDialog(QWidget *parent)
  37. : MainPage(parent)
  38. {
  39. /* Invoke the Qt Designer generated object setup routine */
  40. ui.setupUi(this);
  41. mTimer = NULL;
  42. mInviteTimer = NULL;
  43. /* we use a flag to setup the GettingStarted Flags, so that RS has a bit of time to initialise itself
  44. */
  45. mFirstShow = true;
  46. connect(ui.inviteCheckBox, SIGNAL(stateChanged( int )), this, SLOT(tickInviteChanged()));
  47. connect(ui.addCheckBox, SIGNAL(stateChanged( int )), this, SLOT(tickAddChanged()));
  48. connect(ui.connectCheckBox, SIGNAL(stateChanged( int )), this, SLOT(tickConnectChanged()));
  49. connect(ui.firewallCheckBox, SIGNAL(stateChanged( int )), this, SLOT(tickFirewallChanged()));
  50. connect(ui.pushButton_InviteFriends, SIGNAL(clicked( bool )), this, SLOT(inviteFriends()));
  51. connect(ui.pushButton_AddFriend, SIGNAL(clicked( bool )), this, SLOT(addFriends()));
  52. connect(ui.pushButton_FAQ, SIGNAL(clicked( bool )), this, SLOT(OpenFAQ()));
  53. connect(ui.pushButton_Forums, SIGNAL(clicked( bool )), this, SLOT(OpenForums()));
  54. connect(ui.pushButton_Website, SIGNAL(clicked( bool )), this, SLOT(OpenWebsite()));
  55. connect(ui.pushButton_EmailFeedback, SIGNAL(clicked( bool )), this, SLOT(emailFeedback()));
  56. connect(ui.pushButton_EmailSupport, SIGNAL(clicked( bool )), this, SLOT(emailSupport()));
  57. }
  58. GetStartedDialog::~GetStartedDialog()
  59. {
  60. }
  61. void GetStartedDialog::changeEvent(QEvent *e)
  62. {
  63. switch (e->type()) {
  64. case QEvent::LanguageChange:
  65. ui.retranslateUi(this);
  66. break;
  67. default:
  68. break;
  69. }
  70. }
  71. void GetStartedDialog::showEvent ( QShowEvent * /*event*/ )
  72. {
  73. /* do nothing if locked, or not visible */
  74. if (RsAutoUpdatePage::eventsLocked() == true)
  75. {
  76. std::cerr << "GetStartedDialog::showEvent() events Are Locked" << std::endl;
  77. return;
  78. }
  79. if ((mFirstShow) && (rsConfig))
  80. {
  81. RsAutoUpdatePage::lockAllEvents();
  82. updateFromUserLevel();
  83. mFirstShow = false;
  84. RsAutoUpdatePage::unlockAllEvents() ;
  85. }
  86. }
  87. void GetStartedDialog::updateFromUserLevel()
  88. {
  89. uint32_t userLevel = RSCONFIG_USER_LEVEL_NEW;
  90. userLevel = rsConfig->getUserLevel();
  91. ui.inviteCheckBox->setChecked(false);
  92. ui.addCheckBox->setChecked(false);
  93. ui.connectCheckBox->setChecked(false);
  94. ui.firewallCheckBox->setChecked(false);
  95. switch(userLevel)
  96. {
  97. // FALLS THROUGH EVERYWHERE.
  98. case RSCONFIG_USER_LEVEL_POWER:
  99. case RSCONFIG_USER_LEVEL_OVERRIDE:
  100. ui.firewallCheckBox->setChecked(true);
  101. case RSCONFIG_USER_LEVEL_CASUAL:
  102. ui.connectCheckBox->setChecked(true);
  103. case RSCONFIG_USER_LEVEL_BASIC:
  104. ui.addCheckBox->setChecked(true);
  105. ui.inviteCheckBox->setChecked(true);
  106. default:
  107. case RSCONFIG_USER_LEVEL_NEW:
  108. break;
  109. }
  110. /* will this auto trigger changes? */
  111. }
  112. void GetStartedDialog::tickInviteChanged()
  113. {
  114. if (ui.inviteCheckBox->isChecked())
  115. {
  116. ui.inviteTextBrowser->setVisible(false);
  117. }
  118. else
  119. {
  120. ui.inviteTextBrowser->setVisible(true);
  121. }
  122. }
  123. void GetStartedDialog::tickAddChanged()
  124. {
  125. if (ui.addCheckBox->isChecked())
  126. {
  127. ui.addTextBrowser->setVisible(false);
  128. }
  129. else
  130. {
  131. ui.addTextBrowser->setVisible(true);
  132. }
  133. }
  134. void GetStartedDialog::tickConnectChanged()
  135. {
  136. if (ui.connectCheckBox->isChecked())
  137. {
  138. ui.connectTextBrowser->setVisible(false);
  139. }
  140. else
  141. {
  142. ui.connectTextBrowser->setVisible(true);
  143. }
  144. }
  145. void GetStartedDialog::tickFirewallChanged()
  146. {
  147. if (ui.firewallCheckBox->isChecked())
  148. {
  149. ui.firewallTextBrowser->setVisible(false);
  150. }
  151. else
  152. {
  153. ui.firewallTextBrowser->setVisible(true);
  154. }
  155. }
  156. static void sendMail(const QString &address, const QString &subject, QString body)
  157. {
  158. /* Only under windows do we need to do this! */
  159. #ifdef Q_OS_WIN
  160. /* search and replace the end of lines with: "%0D%0A" */
  161. body.replace("\n", "%0D%0A");
  162. #endif
  163. QString mailstr = "mailto:" + address;
  164. mailstr += "?subject=" + subject;
  165. mailstr += "&body=" + body;
  166. std::cerr << "MAIL STRING:" << mailstr.toStdString() << std::endl;
  167. /* pass the url directly to QDesktopServices::openUrl */
  168. QDesktopServices::openUrl(QUrl(mailstr));
  169. }
  170. void GetStartedDialog::addFriends()
  171. {
  172. ConnectFriendWizard connwiz(this);
  173. connwiz.show();
  174. connwiz.next();
  175. connwiz.exec();
  176. }
  177. void GetStartedDialog::inviteFriends()
  178. {
  179. if (RsAutoUpdatePage::eventsLocked() == true)
  180. {
  181. std::cerr << "GetStartedDialog::inviteFriends() EventsLocked... waiting";
  182. std::cerr << std::endl;
  183. if (!mInviteTimer)
  184. {
  185. mInviteTimer = new QTimer(this);
  186. mInviteTimer->connect(mTimer, SIGNAL(timeout()), this, SLOT(inviteFriends()));
  187. mInviteTimer->setInterval(100); /* 1/10 second */
  188. mInviteTimer->setSingleShot(true);
  189. }
  190. mInviteTimer->start();
  191. return;
  192. }
  193. std::string cert;
  194. {
  195. RsAutoUpdatePage::lockAllEvents();
  196. cert = rsPeers->GetRetroshareInvite(false);
  197. RsAutoUpdatePage::unlockAllEvents() ;
  198. }
  199. QString text = QString("%1\n%2\n\n%3\n").arg(GetInviteText()).arg(GetCutBelowText()).arg(QString::fromUtf8(cert.c_str()));
  200. sendMail("", tr("RetroShare Invitation"), text);
  201. }
  202. QString GetStartedDialog::GetInviteText()
  203. {
  204. QString text = tr("Your friend has installed RetroShare, and would like you to try it out.") + "\n";
  205. text += "\n";
  206. text += tr("You can get RetroShare here: %1").arg(URL_DOWNLOAD) + "\n";
  207. text += "\n";
  208. text += tr("RetroShare is a private Friend-2-Friend sharing network.") + "\n";
  209. text += tr("It has many features, including built-in chat, messaging,") + "\n";
  210. text += tr("forums and channels, all of which are as secure as the file-sharing.") + "\n";
  211. text += "\n";
  212. text += "\n";
  213. text += tr("Here is your friends ID Certificate.") + "\n";
  214. text += tr("Cut and paste the text below into your RetroShare client") + "\n";
  215. text += tr("and send them your ID Certificate to get securely connected.") + "\n";
  216. return text;
  217. }
  218. QString GetStartedDialog::GetCutBelowText()
  219. {
  220. return QString("%1 <-------------------------------------------------------------------------------------").arg(tr("Cut Below Here"));
  221. }
  222. void GetStartedDialog::emailSubscribe()
  223. {
  224. // when translation is needed, replace QString by tr
  225. QString text = QString("Please let me know when RetroShare has a new release, or exciting news") + "\n";
  226. text += "\n";
  227. text += QString("Furthermore, I'd like to say ...") + "\n";
  228. text += "\n";
  229. sendMail(EMAIL_SUBSCRIBE, "Subscribe", text);
  230. }
  231. void GetStartedDialog::emailUnsubscribe()
  232. {
  233. // when translation is needed, replace QString by tr
  234. QString text = QString("I am no longer interested in RetroShare News.") + "\n";
  235. text += QString("Please remove me from the Mailing List") + "\n";
  236. sendMail(EMAIL_SUBSCRIBE, "Unsubscribe", text);
  237. }
  238. void GetStartedDialog::emailFeedback()
  239. {
  240. // when translation is needed, replace QString by tr
  241. QString text = QString("Dear RetroShare Developers") + "\n";
  242. text += "\n";
  243. text += QString("I've tried out RetroShare and would like provide feedback:") + "\n";
  244. text += "\n";
  245. text += QString("To make RetroShare more user friendly, please [ what do you think? ] ") + "\n";
  246. text += QString("The best feature of RetroShare is [ what do you think? ] ") + "\n";
  247. text += QString("and the biggest missing feature is [ what do you think? ] ") + "\n";
  248. text += "\n";
  249. text += QString("Furthermore, I'd like to say ... ") + "\n";
  250. text += "\n";
  251. sendMail("feedback@retroshare.org", tr("RetroShare Feedback"), text);
  252. }
  253. void GetStartedDialog::emailSupport()
  254. {
  255. if (RsAutoUpdatePage::eventsLocked() == true)
  256. {
  257. std::cerr << "GetStartedDialog::emailSupport() EventsLocked... waiting";
  258. std::cerr << std::endl;
  259. if (!mTimer)
  260. {
  261. mTimer = new QTimer(this);
  262. mTimer->connect(mTimer, SIGNAL(timeout()), this, SLOT(emailSupport()));
  263. mTimer->setInterval(100); /* 1/10 second */
  264. mTimer->setSingleShot(true);
  265. }
  266. mTimer->start();
  267. return;
  268. }
  269. uint32_t userLevel;
  270. {
  271. RsAutoUpdatePage::lockAllEvents();
  272. userLevel = rsConfig->getUserLevel();
  273. RsAutoUpdatePage::unlockAllEvents() ;
  274. }
  275. // when translation is needed, replace QString by tr
  276. QString text = QString("Hello") + "\n";
  277. text += "\n";
  278. QString sysVersion;
  279. #ifdef __APPLE__
  280. #ifdef Q_OS_MAC
  281. switch(QSysInfo::MacintoshVersion)
  282. {
  283. case QSysInfo::MV_9:
  284. sysVersion = "Mac OS 9";
  285. break;
  286. case QSysInfo::MV_10_0:
  287. sysVersion = "Mac OSX 10.0";
  288. break;
  289. case QSysInfo::MV_10_1:
  290. sysVersion = "Mac OSX 10.1";
  291. break;
  292. case QSysInfo::MV_10_2:
  293. sysVersion = "Mac OSX 10.2";
  294. break;
  295. case QSysInfo::MV_10_3:
  296. sysVersion = "Mac OSX 10.3";
  297. break;
  298. case QSysInfo::MV_10_4:
  299. sysVersion = "Mac OSX 10.4";
  300. break;
  301. case QSysInfo::MV_10_5:
  302. sysVersion = "Mac OSX 10.5";
  303. break;
  304. case QSysInfo::MV_10_6:
  305. sysVersion = "Mac OSX 10.6";
  306. break;
  307. // case QSysInfo::MV_10_7:
  308. // sysVersion = "Mac OSX 10.7";
  309. // break;
  310. default:
  311. sysVersion = "Mac Unknown";
  312. break;
  313. }
  314. #else
  315. sysVersion = "OSX Unknown";
  316. #endif
  317. #else
  318. #if defined(_WIN32) || defined(__MINGW32__)
  319. // Windows
  320. #ifdef Q_OS_WIN
  321. switch(QSysInfo::windowsVersion())
  322. {
  323. case QSysInfo::WV_32s:
  324. sysVersion = "Windows 2.1";
  325. break;
  326. case QSysInfo::WV_95:
  327. sysVersion = "Windows 95";
  328. break;
  329. case QSysInfo::WV_98:
  330. sysVersion = "Windows 98";
  331. break;
  332. case QSysInfo::WV_Me:
  333. sysVersion = "Windows Me";
  334. break;
  335. case QSysInfo::WV_NT:
  336. sysVersion = "Windows NT";
  337. break;
  338. case QSysInfo::WV_2000:
  339. sysVersion = "Windows 2000";
  340. break;
  341. case QSysInfo::WV_XP:
  342. sysVersion = "Windows XP";
  343. break;
  344. case QSysInfo::WV_2003:
  345. sysVersion = "Windows 2003";
  346. break;
  347. case QSysInfo::WV_VISTA:
  348. sysVersion = "Windows Vista";
  349. break;
  350. case QSysInfo::WV_WINDOWS7:
  351. sysVersion = "Windows 7";
  352. break;
  353. default:
  354. sysVersion = "Windows";
  355. break;
  356. }
  357. #else
  358. sysVersion = "Windows Unknown";
  359. #endif
  360. #else
  361. // Linux
  362. sysVersion = "Linux";
  363. #endif
  364. #endif
  365. text += QString("My RetroShare Configuration is: (%1, %2, 0x60%3)").arg(Rshare::retroshareVersion(true)).arg(sysVersion).arg(userLevel) + "\n";
  366. text += "\n";
  367. text += QString("I am having trouble with RetroShare.");
  368. text += QString(" Can you help me with....") + "\n";
  369. text += "\n";
  370. sendMail("support@retroshare.org", tr("RetroShare Support"), text);
  371. }
  372. void GetStartedDialog::OpenFAQ()
  373. {
  374. /* pass the url directly to QDesktopServices::openUrl */
  375. QDesktopServices::openUrl(QUrl(URL_FAQ));
  376. }
  377. void GetStartedDialog::OpenForums()
  378. {
  379. /* pass the url directly to QDesktopServices::openUrl */
  380. QDesktopServices::openUrl(QUrl(URL_FORUM));
  381. }
  382. void GetStartedDialog::OpenWebsite()
  383. {
  384. /* pass the url directly to QDesktopServices::openUrl */
  385. QDesktopServices::openUrl(QUrl(URL_WEBSITE));
  386. }