PageRenderTime 89ms CodeModel.GetById 43ms RepoModel.GetById 1ms app.codeStats 1ms

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

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