PageRenderTime 62ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/statusbrowser.cpp

https://github.com/plus7/Qween
C++ | 112 lines | 75 code | 10 blank | 27 comment | 4 complexity | f5a561273ed866f7adda8a03286c4acf MD5 | raw file
  1. /*
  2. This file is part of Qween.
  3. Copyright (C) 2009-2010 NOSE Takafumi <ahya365@gmail.com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. In addition, as a special exception, NOSE Takafumi
  15. gives permission to link the code of its release of Qween with the
  16. OpenSSL project's "OpenSSL" library (or with modified versions of it
  17. that use the same license as the "OpenSSL" library), and distribute
  18. the linked executables. You must obey the GNU General Public License
  19. in all respects for all of the code used other than "OpenSSL". If you
  20. modify this file, you may extend this exception to your version of the
  21. file, but you are not obligated to do so. If you do not wish to do
  22. so, delete this exception statement from your version.
  23. */
  24. #include "statusbrowser.h"
  25. #include <QtGui>
  26. #include <QtCore>
  27. #include "qweenapplication.h"
  28. #include "thumbmanager.h"
  29. StatusBrowser::StatusBrowser(QWidget *parent) :
  30. QTextBrowser(parent)
  31. {
  32. }
  33. void StatusBrowser::contextMenuEvent(QContextMenuEvent *event)
  34. {
  35. QMenu *menu = createStandardContextMenu(event->pos());
  36. m_selectedName.clear();
  37. if(!event->pos().isNull()){
  38. QString tmp = anchorAt(event->pos());
  39. QRegExp rx("^https?://twitter\\.com/([a-zA-Z0-9_]+)$");
  40. if(tmp.indexOf(rx)>=0){
  41. m_selectedName = rx.cap(1);
  42. }
  43. }
  44. if(this->textCursor().hasSelection()){
  45. QAction *a = menu->actions().at(2);
  46. QMenu *m = new QMenu(tr("Web Search"),menu);
  47. m->addAction(tr("Google"), this, SLOT(searchGoogleClicked()));
  48. m->addAction(tr("Wikipedia"), this, SLOT(searchWpClicked()));
  49. m->addAction(tr("twitter検索(公式)"), this, SLOT(searchTwitterClicked()));
  50. m->addAction(tr("twitter検索(yats)"), this, SLOT(searchYatsClicked()));
  51. menu->insertMenu(a, m);
  52. }
  53. if(!m_selectedName.isEmpty()){
  54. menu->addSeparator();
  55. menu->addAction(tr("Follow"),this, SLOT(followClicked()));
  56. menu->addAction(tr("Remove"),this, SLOT(removeClicked()));
  57. menu->addAction(tr("ShowFriendship"),this, SLOT(friendshipClicked()));
  58. }
  59. menu->exec(event->globalPos());
  60. delete menu;
  61. }
  62. void StatusBrowser::searchGoogleClicked(){
  63. QDesktopServices::openUrl(
  64. QUrl(QString("http://www.google.co.jp/search?hl=ja&q=%1")
  65. .arg(textCursor().selection().toPlainText())));
  66. }
  67. void StatusBrowser::searchYatsClicked(){
  68. QDesktopServices::openUrl(
  69. QUrl(QString("http://pcod.no-ip.org/yats/search?query=%1")
  70. .arg(textCursor().selection().toPlainText())));
  71. }
  72. void StatusBrowser::searchTwitterClicked(){
  73. QDesktopServices::openUrl(
  74. QUrl(QString("http://search.twitter.com/search?q=%1")
  75. .arg(textCursor().selection().toPlainText())));
  76. }
  77. void StatusBrowser::searchWpClicked(){
  78. QDesktopServices::openUrl(
  79. QUrl(QString("http://ja.wikipedia.org/w/index.php?search=%1&fulltext=%E6%A4%9C%E7%B4%A2")
  80. .arg(textCursor().selection().toPlainText())));
  81. }
  82. void StatusBrowser::followClicked(){
  83. emit followCommand(m_selectedName);
  84. }
  85. void StatusBrowser::removeClicked(){
  86. emit removeCommand(m_selectedName);
  87. }
  88. void StatusBrowser::friendshipClicked(){
  89. emit friendshipCommand(m_selectedName);
  90. }
  91. void StatusBrowser::thumbFetched(const QString& uri){
  92. QString before(">%1<");
  93. before = before.arg(uri);
  94. QString after("><img src=\"%1\"><");
  95. after = after.arg(QweenApplication::thumbManager()->getThumbFilePath(uri));
  96. QString hoge = toHtml().replace(before, after);
  97. setHtml(hoge);
  98. }