Changeset 558:30b0989e5b4e in qutecom-2.2
- Timestamp:
- Mar 8, 2010 12:24:29 PM (3 years ago)
- Branch:
- default
- Location:
- wengophone
- Files:
-
- 2 added
- 9 edited
-
resources/chat/base.html (added)
-
resources/chat/translate.html (added)
-
resources/config/config.xml (modified) (1 diff)
-
src/model/config/Config.cpp (modified) (2 diffs)
-
src/model/config/Config.h (modified) (1 diff)
-
src/presentation/qt/chat/QtChatHistoryWidget.cpp (modified) (10 diffs)
-
src/presentation/qt/chat/QtChatHistoryWidget.h (modified) (1 diff)
-
src/presentation/qt/chat/QtChatWidget.cpp (modified) (6 diffs)
-
src/presentation/qt/chat/QtChatWidget.h (modified) (6 diffs)
-
src/presentation/qt/config/LanguagesSettings.ui (modified) (1 diff)
-
src/presentation/qt/config/QtLanguagesSettings.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wengophone/resources/config/config.xml
r488 r558 272 272 <feature.sms><bool>1</bool></feature.sms> 273 273 <feature.audioconference><bool>1</bool></feature.audioconference> 274 274 <translation.sent><string>unknow</string></translation.sent> 275 <translation.received><string>unknow</string></translation.received> 275 276 </settings> -
wengophone/src/model/config/Config.cpp
r522 r558 209 209 const string Config::SIP_USE_TYPING_STATE="sip.use.typing_state"; 210 210 211 const string Config::TRANSLATION_SENT_KEY="translation.sent"; 212 const string Config::TRANSLATION_RECEIVED_KEY="translation.received"; 213 211 214 string Config::_configDir; 212 215 … … 819 822 return getBooleanKeyValue(SIP_USE_TYPING_STATE); 820 823 } 824 825 string Config::getTranslationSent() const { 826 return getStringKeyValue(TRANSLATION_SENT_KEY); 827 } 828 829 string Config::getTranslationReceived() const { 830 return getStringKeyValue(TRANSLATION_RECEIVED_KEY); 831 } -
wengophone/src/model/config/Config.h
r522 r558 656 656 /** @} */ 657 657 658 /** 659 * @name translation Methods 660 * @{ 661 */ 662 663 static const std::string TRANSLATION_SENT_KEY; 664 std::string getTranslationSent() const; 665 666 static const std::string TRANSLATION_RECEIVED_KEY; 667 std::string getTranslationReceived() const; 668 658 669 private: 659 670 -
wengophone/src/presentation/qt/chat/QtChatHistoryWidget.cpp
r516 r558 65 65 page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); 66 66 connect(this,SIGNAL(linkClicked(const QUrl &)),this,SLOT(urlClicked(const QUrl &))); 67 68 //load(QUrl("/Users/laurent/Desktop/qutecom-2.2/debug/debug/QuteCom.app/Contents/Resources/chat/base.html")); 67 69 } 68 70 … … 73 75 void QtChatHistoryWidget::setTheme(const QString& themeDir) { 74 76 _theme->load(themeDir); 77 Config & config = ConfigManager::getInstance().getCurrentConfig(); 75 78 76 79 QFile file(_theme->getCurrentThemePath()+"/main.css"); … … 78 81 QUrl url_css("data:text/css;charset=utf-8;base64,"+file.readAll().toBase64()); 79 82 page()->settings()->setUserStyleSheetUrl(url_css); 83 84 page()->mainFrame()->addToJavaScriptWindowObject("parent",this); 85 QFile file_base(QString::fromStdString(config.getResourcesDir())+"chat/base.html"); 86 file_base.open(QIODevice::ReadOnly); 87 #if defined(OS_WINDOWS) 88 setHtml(file_base.readAll(),QUrl(_theme->getCurrentThemePath())); 89 #else 90 setHtml(file_base.readAll(),QUrl("file://"+_theme->getCurrentThemePath())); 91 #endif 92 80 93 } 81 94 … … 113 126 114 127 void QtChatHistoryWidget::insertMessage(const QString & contactId, const QString & senderName, const QString & message, const QTime & time) { 115 //QTextCursor curs(document()); 116 //curs.movePosition(QTextCursor::End); 117 //setTextCursor(curs); 118 128 119 129 // Prepare message 120 130 QString htmlMessage = QtChatUtils::decodeMessage(_protocol, message); 131 Config & config = ConfigManager::getInstance().getCurrentConfig(); 132 133 page ()->currentFrame ()->evaluateJavaScript("setLanguage(\""+QString::fromStdString(config.getTranslationReceived())+"\")"); 121 134 122 135 // Get html … … 131 144 if (!_lastSenderName.isEmpty()) 132 145 { 133 _data += _theme->getFooter(); 146 QString footer = _theme->getFooter(); 147 footer = footer.replace("\n",""); 148 footer = footer.replace("\r",""); 149 footer = footer.replace("\t",""); 150 footer = footer.replace("\"","\\\""); 151 footer = footer.replace("\'","\\\'"); 152 page ()->currentFrame ()->evaluateJavaScript("insertMessageAtEnd(\""+footer+"\")"); 134 153 } 135 154 position = QtChatTheme::First; … … 149 168 QtChatTheme::setKeywordValue(html, "sender", senderName); 150 169 QtChatTheme::setKeywordValue(html, "time", time.toString("HH:mm")); 151 QtChatTheme::setKeywordValue(html, "message", htmlMessage);170 QtChatTheme::setKeywordValue(html, "message", "<div id='magic_id'>"+htmlMessage+"</div>"); 152 171 QtChatTheme::setKeywordValue(html, "service", ""); 153 172 … … 156 175 avatar_path = _avatarMap[contactId]; 157 176 QtChatTheme::setKeywordValue(html, "userIconPath", avatar_path); 158 159 QString theme_insert1 = "<span id=\"insert\"></span>"; 160 QString theme_insert2 = "<div id=\"insert\"></div>"; 161 162 if(position == QtChatTheme::Next && html.contains(theme_insert1)) 163 { 164 _data.insert(_data.lastIndexOf(theme_insert1),html); 165 } 166 else if (position == QtChatTheme::Next && html.contains(theme_insert2)) 167 { 168 _data.insert(_data.lastIndexOf(theme_insert2),html); 169 } 177 178 //updateHtml(); 179 180 html = html.replace("\n",""); 181 html = html.replace("\r",""); 182 html = html.replace("\t",""); 183 html = html.replace("\"","\\\""); 184 html = html.replace("\'","\\\'"); 185 if(position == QtChatTheme::Next) 186 page ()->currentFrame ()->evaluateJavaScript("insertMessage(\""+html+"\")"); 170 187 else 171 _data += html;172 173 updateHtml();188 page ()->currentFrame ()->evaluateJavaScript("insertMessageAtEnd(\""+html+"\")"); 189 190 //scrollToBottom(); 174 191 } 175 192 … … 177 194 // Make sure we close any opened message group 178 195 if (!_lastSenderName.isEmpty()) { 179 _data += _theme->getFooter(); 196 QString footer = _theme->getFooter(); 197 page ()->currentFrame ()->evaluateJavaScript("insertMessageAtEnd(\""+footer+"\")"); 180 198 _lastSenderName = ""; 181 199 } … … 184 202 QtChatTheme::setKeywordValue(html, "time", time.toString("HH:mm")); 185 203 186 Config & config = ConfigManager::getInstance().getCurrentConfig(); 187 QString themeDir = QString::fromStdString(config.getChatTheme()); 188 189 _data += html; 190 191 updateHtml(); 204 html = html.replace("\n",""); 205 html = html.replace("\r",""); 206 html = html.replace("\t",""); 207 html = html.replace("\"","\\\""); 208 html = html.replace("\'","\\\'"); 209 page ()->currentFrame ()->evaluateJavaScript("insertMessageAtEnd(\""+html+"\")"); 210 211 //_data += html; 212 192 213 } 193 214 194 215 void QtChatHistoryWidget::setAvatarPixmap(const QString& name, const QPixmap& pixmap) 195 216 { 196 QString path = QDir::temp().absolutePath()+QDir::separator()+name+".png"; 217 QDir dir(QString::fromStdString(Config::getConfigDir())); 218 219 if(!dir.exists("cache")) 220 dir.mkdir("cache"); 221 dir.cd("cache"); 222 223 QString path = dir.absolutePath()+QDir::separator()+name+".png"; 224 197 225 pixmap.save(path,"PNG"); 198 _avatarMap[name] = path; 199 } 200 201 /*QVariant QtChatHistoryWidget::loadResource(int type, const QUrl& url) { 202 if (type != QTextDocument::ImageResource || url.scheme() != "avatar") { 203 return QTextBrowser::loadResource(type, url); 204 } 205 206 QString userId = url.path(); 207 if (!_avatarMap.contains(userId)) { 208 std::string data = AvatarList::getInstance().getDefaultAvatarPicture().getData(); 209 QPixmap pixmap; 210 pixmap.loadFromData((uchar *)data.c_str(), data.size()); 211 _avatarMap[userId] = pixmap; 212 } 213 QPixmap pixmap = _avatarMap[userId]; 214 215 if (!pixmap.isNull()) { 216 QString sizeString = url.queryItemValue("size"); 217 bool ok; 218 int size = sizeString.toInt(&ok); 219 if (ok) { 220 if (_scaledAvatarCache.contains(url)) { 221 pixmap = _scaledAvatarCache[url]; 222 } else { 223 pixmap = pixmap.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation); 224 _scaledAvatarCache[url] = pixmap; 225 } 226 } 227 } 228 229 return QVariant(pixmap); 230 }*/ 226 _avatarMap[name] = "file://"+path; 227 } 231 228 232 229 void QtChatHistoryWidget::scrollToBottom() { 233 // We do not use ensureCursorVisible() because it cause the view to get 234 // scrolled horizontally if the last line does not fit the view. 235 //verticalScrollBar()->setValue(verticalScrollBar()->maximum()); 230 236 231 QWebFrame * frame = page()->mainFrame (); 237 232 frame->setScrollBarValue(Qt::Vertical,frame->scrollBarMaximum(Qt::Vertical)); … … 244 239 } 245 240 246 void QtChatHistoryWidget::slot_loadFinished(bool)247 {248 scrollToBottom();249 }250 241 251 242 void QtChatHistoryWidget::updateHtml() -
wengophone/src/presentation/qt/chat/QtChatHistoryWidget.h
r503 r558 75 75 */ 76 76 void urlClicked(const QUrl & link); 77 78 public Q_SLOTS: 79 void scrollToBottom(); 77 80 78 void scrollToBottom();79 80 void slot_loadFinished(bool);81 82 81 private: 83 82 void updateHtml(); -
wengophone/src/presentation/qt/chat/QtChatWidget.cpp
r503 r558 65 65 static const int EMOTICON_OFFSET_Y = 30; 66 66 67 QString clearHtml( const QString & str) 68 { 69 QString html = str; 70 71 QRegExp htmlDocumentToHtmlSnippet(".*<body[^>]*>\\s*<p[^>]*>(.*)</p>\\s*</body>\\s*</html>"); 72 QRegExp pTag("<p[^>]*>"); 73 74 // toHtml() returns an HTML document, complete with html and body tags. 75 // This regexp strip those to produce an HTML snippet, which can be 76 // concatenated to the existing history 77 html.replace(htmlDocumentToHtmlSnippet, "\\1"); 78 html.replace(pTag, "<div>"); 79 html.replace("</p>", "</div>"); 80 81 return html; 82 } 83 67 84 QtChatWidget::QtChatWidget(CChatHandler & cChatHandler, 68 85 QtWengoPhone * qtWengoPhone, int sessionId, … … 136 153 SAFE_CONNECT_TYPE(this, SIGNAL(profileChangedEventHandlerSignal()), 137 154 SLOT(updateUserAvatar()), Qt::QueuedConnection); 155 156 _webView = new QWebView; 157 _webView->page()->mainFrame()->addToJavaScriptWindowObject("parent",this); 158 Config & config = ConfigManager::getInstance().getCurrentConfig(); 159 QFile file(QString::fromStdString(config.getResourcesDir())+"chat/translate.html"); 160 file.open(QIODevice::ReadOnly); 161 _webView->setHtml(file.readAll()); 138 162 } 139 163 … … 142 166 143 167 _stoppedTypingTimer->stop(); 168 169 delete _webView; 144 170 } 145 171 … … 185 211 _underline = !_underline; 186 212 _ui.chatEdit->setFontUnderline(_underline); 213 } 214 215 void QtChatWidget::translateClickedSlot() 216 { 217 Config & config = ConfigManager::getInstance().getCurrentConfig(); 218 QString lang = QString::fromStdString(config.getTranslationSent()); 219 QString text = clearHtml(_ui.chatEdit->toHtml()); 220 221 if(text.isEmpty() || lang == "unknow") 222 return; 223 224 text = text.replace("\"","\\\""); 225 text = text.replace("\'","\\\'"); 226 227 _webView->page ()->mainFrame ()->evaluateJavaScript("setLanguage(\""+QString::fromStdString(config.getTranslationSent())+"\")"); 228 _webView->page ()->mainFrame ()->evaluateJavaScript("translate(\""+text+"\")"); 187 229 } 188 230 … … 292 334 } 293 335 294 void QtChatWidget::sendMessage() { 295 QRegExp htmlDocumentToHtmlSnippet(".*<body[^>]*>\\s*<p[^>]*>(.*)</p>\\s*</body>\\s*</html>"); 296 QRegExp pTag("<p[^>]*>"); 297 336 void QtChatWidget::sendMessage() 337 { 338 Config & config = ConfigManager::getInstance().getCurrentConfig(); 339 QString lang = QString::fromStdString(config.getTranslationSent()); 340 341 if(lang=="unknow") 342 sendMessage(_ui.chatEdit->toHtml()); 343 else 344 translateClickedSlot(); 345 } 346 347 void QtChatWidget::sendMessage(const QString & text) { 348 349 QString html = clearHtml(text); 298 350 //Drop empty message 299 if ( _ui.chatEdit->toPlainText().isEmpty()) {351 if (html.isEmpty()) { 300 352 return; 301 353 } 302 303 QString html = _ui.chatEdit->toHtml();304 // toHtml() returns an HTML document, complete with html and body tags.305 // This regexp strip those to produce an HTML snippet, which can be306 // concatenated to the existing history307 html.replace(htmlDocumentToHtmlSnippet, "\\1");308 html.replace(pTag, "<div>");309 html.replace("</p>", "</div>");310 354 311 355 addToHistory("self", _nickName, html); … … 372 416 _imChatSession->changeTypingState(IMChat::TypingStateStopTyping); 373 417 _isTyping = false; 418 } 419 420 void QtChatWidget::translateFinishedSlot(const QVariant & var) 421 { 422 QString str = var.toString(); 423 str = str.replace("'","'"); 424 sendMessage(str); 374 425 } 375 426 -
wengophone/src/presentation/qt/chat/QtChatWidget.h
r0 r558 34 34 35 35 #include <QtCore/QTime> 36 #include <QtWebKit/QWebView> 36 37 37 38 class Profile; … … 43 44 class QTimer; 44 45 46 #include <QtNetwork/QtNetwork> 47 45 48 /** 46 49 * … … 137 140 138 141 void sendFileToSession(const QString & filename); 142 143 void translateFinishedSlot(const QVariant & ); 139 144 140 145 Q_SIGNALS: … … 172 177 173 178 void updateUserAvatar(); 179 180 void translateClickedSlot(); 174 181 175 182 private: … … 185 192 186 193 bool editKeyPressEventFilter(QKeyEvent* event); 194 195 void sendMessage(const QString & html); 187 196 188 197 CChatHandler & _cChatHandler; … … 221 230 222 231 bool _isTyping; 232 233 QWebView * _webView; 223 234 }; 224 235 -
wengophone/src/presentation/qt/config/LanguagesSettings.ui
r0 r558 1 <ui version="4.0" > 1 <?xml version="1.0" encoding="UTF-8"?> 2 <ui version="4.0"> 2 3 <class>LanguagesSettings</class> 3 <widget class="QWidget" name="LanguagesSettings" >4 <property name="geometry" >4 <widget class="QWidget" name="LanguagesSettings"> 5 <property name="geometry"> 5 6 <rect> 6 7 <x>0</x> 7 8 <y>0</y> 8 <width> 489</width>9 <height> 392</height>9 <width>535</width> 10 <height>493</height> 10 11 </rect> 11 12 </property> 12 <layout class="QVBoxLayout" > 13 <property name="margin" > 14 <number>9</number> 15 </property> 16 <property name="spacing" > 17 <number>6</number> 18 </property> 19 <item> 20 <widget class="QListWidget" name="listWidget" /> 13 <layout class="QGridLayout" name="gridLayout_2"> 14 <item row="0" column="0"> 15 <widget class="QListWidget" name="listWidget"/> 21 16 </item> 22 <item> 23 <widget class="QLabel" name="label" > 24 <property name="text" > 17 <item row="1" column="0"> 18 <widget class="QGroupBox" name="groupBox"> 19 <property name="title"> 20 <string>Google Translate</string> 21 </property> 22 <layout class="QGridLayout" name="gridLayout"> 23 <item row="0" column="0"> 24 <widget class="QLabel" name="label_2"> 25 <property name="text"> 26 <string>language to convert the messages received</string> 27 </property> 28 </widget> 29 </item> 30 <item row="0" column="1"> 31 <widget class="QComboBox" name="comboBox_received"> 32 <property name="frame"> 33 <bool>true</bool> 34 </property> 35 </widget> 36 </item> 37 <item row="1" column="0"> 38 <widget class="QLabel" name="label_3"> 39 <property name="text"> 40 <string>language to convert the messages sent</string> 41 </property> 42 </widget> 43 </item> 44 <item row="1" column="1"> 45 <widget class="QComboBox" name="comboBox_sent"/> 46 </item> 47 </layout> 48 </widget> 49 </item> 50 <item row="2" column="0"> 51 <widget class="QLabel" name="label"> 52 <property name="text"> 25 53 <string>Your language is not here, do you know that you can do your own translation on Launchpad?</string> 26 54 </property> 27 <property name="wordWrap" >55 <property name="wordWrap"> 28 56 <bool>true</bool> 29 57 </property> 30 58 </widget> 31 59 </item> 32 <item >33 <widget class="LinkLabel" name="launchpadLink" >34 <property name="text" >60 <item row="3" column="0"> 61 <widget class="LinkLabel" name="launchpadLink"> 62 <property name="text"> 35 63 <string>More information here.</string> 36 64 </property> -
wengophone/src/presentation/qt/config/QtLanguagesSettings.cpp
r0 r558 48 48 _ui->listWidget->addItems(QtLanguage::getAvailableLanguages()); 49 49 50 QStringList list; 51 list << "unknow" << "sq" <<"ar" <<"bg" <<"ca" 52 <<"zh-CN" <<"zh-TW" <<"hr" 53 <<"cs" <<"da" <<"nl" <<"en" 54 <<"et" <<"tl" <<"fi" <<"fr" 55 <<"gl" <<"de" <<"el" <<"iw" 56 <<"hi" <<"hu" <<"id" <<"it" 57 <<"ja" <<"ko" <<"lv" <<"lt" 58 <<"mt" <<"no" <<"pl" <<"pt" 59 <<"ro" <<"ru" <<"sr" <<"sk" 60 <<"sl" <<"es" <<"sv" <<"th" 61 <<"tr" <<"uk" <<"vi"; 62 63 _ui->comboBox_received->addItems (list); 64 _ui->comboBox_sent->addItems (list); 65 50 66 readConfig(); 51 67 } … … 77 93 Config & config = ConfigManager::getInstance().getCurrentConfig(); 78 94 config.set(Config::LANGUAGE_KEY, LanguageList::getISO639Code(language)); 95 96 config.set(Config::TRANSLATION_SENT_KEY, _ui->comboBox_sent->currentText().toStdString()); 97 config.set(Config::TRANSLATION_RECEIVED_KEY, _ui->comboBox_received->currentText().toStdString()); 79 98 } 80 99 … … 87 106 _ui->listWidget->setCurrentItem(list[0]); 88 107 } 108 109 _ui->comboBox_sent->setCurrentIndex(_ui->comboBox_sent->findText(QString::fromStdString(config.getTranslationSent()))); 110 _ui->comboBox_received->setCurrentIndex(_ui->comboBox_received->findText(QString::fromStdString(config.getTranslationReceived()))); 89 111 } 90 112
Note: See TracChangeset
for help on using the changeset viewer.
