void NotifyQt::UpdateGUI() { #ifndef MINIMAL_RSGUI /* hack to force updates until we've fixed that part */ static time_t lastTs = 0; // std::cerr << "Got update signal t=" << lastTs << std::endl ; lastTs = time(NULL) ; static bool already_updated = false ; // these only update once at start because they may already have been set before // the gui is running, then they get updated by callbacks. if(!already_updated) { emit messagesChanged() ; emit neighborsChanged(); emit configChanged(); already_updated = true ; } /* Finally Check for PopupMessages / System Error Messages */ if (rsNotify) { uint32_t sysid; uint32_t type; std::string title, id, msg; if (rsNotify->NotifyPopupMessage(type, id, title, msg)) { uint popupflags = Settings->getNotifyFlags(); /* You can set timeToShow, timeToLive and timeToHide or can leave the standard */ Toaster *toaster = NULL; /* id the name */ std::string name; std::string realmsg; unsigned char *data = NULL; int size = 0 ; if (type == RS_POPUP_DOWNLOAD) { /* id = file hash */ } else { name = rsPeers->getPeerName(id); realmsg = "<strong>" + name + "</strong>"; rsMsgs->getAvatarData(id,data,size); } switch(type) { case RS_POPUP_MSG: if (popupflags & RS_POPUP_MSG) { toaster = new Toaster(new MessageToaster(QString::fromStdString(realmsg), QString::fromStdString(title), QString::fromStdString(msg))); } break; case RS_POPUP_CONNECT: if (popupflags & RS_POPUP_CONNECT) { QPixmap avatar; if(size != 0) { // set the image avatar.loadFromData(data,size,"PNG"); } else { avatar = QPixmap(":/images/user/personal64.png"); } toaster = new Toaster(new OnlineToaster(id, QString::fromStdString(realmsg), avatar)); } break; case RS_POPUP_DOWNLOAD: if (popupflags & RS_POPUP_DOWNLOAD) { toaster = new Toaster(new DownloadToaster(id, QString::fromUtf8(title.c_str()))); } break; } if (data) { delete[] data; } if (toaster) { /* init attributes */ toaster->widget->setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint); /* add toaster to waiting list */ // QMutexLocker lock(&waitingToasterMutex); waitingToasterList.push_back(toaster); } } if (rsNotify->NotifySysMessage(sysid, type, title, msg)) { /* make a warning message */ switch(type) { case RS_SYS_ERROR: QMessageBox::critical(MainWindow::getInstance(), QString::fromStdString(title), QString::fromStdString(msg)); break; case RS_SYS_WARNING: QMessageBox::warning(MainWindow::getInstance(), QString::fromStdString(title), QString::fromStdString(msg)); break; default: case RS_SYS_INFO: QMessageBox::information(MainWindow::getInstance(), QString::fromStdString(title), QString::fromStdString(msg)); break; } } if (rsNotify->NotifyLogMessage(sysid, type, title, msg)) { /* make a log message */ std::string logMesString = title + " " + msg; switch(type) { case RS_SYS_ERROR: case RS_SYS_WARNING: case RS_SYS_INFO: emit logInfoChanged(QString(logMesString.c_str())); default:; } } } /* Now start the waiting toasters */ startWaitingToasters(); #endif // MINIMAL_RSGUI }
void NotifyQt::UpdateGUI() { if(RsAutoUpdatePage::eventsLocked()) return ; { QMutexLocker m(&_mutex) ; if(!_enabled) return ; } static bool already_updated = false ; // these only update once at start because they may already have been set before // the gui is running, then they get updated by callbacks. if(!already_updated) { emit messagesChanged() ; emit neighboursChanged(); emit configChanged(); already_updated = true ; } /* Finally Check for PopupMessages / System Error Messages */ if (rsNotify) { uint32_t sysid; uint32_t type; std::string title, id, msg; /* You can set timeToShow, timeToLive and timeToHide or can leave the standard */ ToasterItem *toaster = NULL; if (rsNotify->NotifyPopupMessage(type, id, title, msg)) { uint popupflags = Settings->getNotifyFlags(); switch(type) { case RS_POPUP_ENCRYPTED_MSG: SoundManager::play(SOUND_MESSAGE_ARRIVED); if ((popupflags & RS_POPUP_MSG) && !_disableAllToaster) { toaster = new ToasterItem(new MessageToaster("", tr("Encrypted message"), QString("[%1]").arg(tr("Encrypted message")))); } break; case RS_POPUP_MSG: SoundManager::play(SOUND_MESSAGE_ARRIVED); if ((popupflags & RS_POPUP_MSG) && !_disableAllToaster) { toaster = new ToasterItem(new MessageToaster(id, QString::fromUtf8(title.c_str()), QString::fromUtf8(msg.c_str()))); } break; case RS_POPUP_CONNECT: SoundManager::play(SOUND_USER_ONLINE); if ((popupflags & RS_POPUP_CONNECT) && !_disableAllToaster) { toaster = new ToasterItem(new OnlineToaster(RsPeerId(id))); } break; case RS_POPUP_DOWNLOAD: SoundManager::play(SOUND_DOWNLOAD_COMPLETE); if ((popupflags & RS_POPUP_DOWNLOAD) && !_disableAllToaster) { /* id = file hash */ toaster = new ToasterItem(new DownloadToaster(RsFileHash(id), QString::fromUtf8(title.c_str()))); } break; case RS_POPUP_CHAT: if ((popupflags & RS_POPUP_CHAT) && !_disableAllToaster) { // TODO: fix for distant chat, look up if dstant chat uses RS_POPUP_CHAT ChatDialog *chatDialog = ChatDialog::getChat(ChatId(RsPeerId(id))); ChatWidget *chatWidget; if (chatDialog && (chatWidget = chatDialog->getChatWidget()) && chatWidget->isActive()) { // do not show when active break; } toaster = new ToasterItem(new ChatToaster(RsPeerId(id), QString::fromUtf8(msg.c_str()))); } break; case RS_POPUP_GROUPCHAT: if ((popupflags & RS_POPUP_GROUPCHAT) && !_disableAllToaster) { MainWindow *mainWindow = MainWindow::getInstance(); if (mainWindow && mainWindow->isActiveWindow() && !mainWindow->isMinimized()) { if (MainWindow::getActivatePage() == MainWindow::Friends) { if (FriendsDialog::isGroupChatActive()) { // do not show when active break; } } } toaster = new ToasterItem(new GroupChatToaster(RsPeerId(id), QString::fromUtf8(msg.c_str()))); } break; case RS_POPUP_CHATLOBBY: if ((popupflags & RS_POPUP_CHATLOBBY) && !_disableAllToaster) { ChatId chat_id(id); ChatDialog *chatDialog = ChatDialog::getChat(chat_id); ChatWidget *chatWidget; if (chatDialog && (chatWidget = chatDialog->getChatWidget()) && chatWidget->isActive()) { // do not show when active break; } ChatLobbyDialog *chatLobbyDialog = dynamic_cast<ChatLobbyDialog*>(chatDialog); RsGxsId sender(title); if (!chatLobbyDialog || chatLobbyDialog->isParticipantMuted(sender)) break; // participant is muted toaster = new ToasterItem(new ChatLobbyToaster(chat_id.toLobbyId(), sender, QString::fromUtf8(msg.c_str()))); } break; case RS_POPUP_CONNECT_ATTEMPT: if ((popupflags & RS_POPUP_CONNECT_ATTEMPT) && !_disableAllToaster) { // id = gpgid // title = ssl name // msg = peer id toaster = new ToasterItem(new FriendRequestToaster(RsPgpId(id), QString::fromUtf8(title.c_str()), RsPeerId(msg))); } break; } } /*Now check Plugins*/ if (!toaster) { int pluginCount = rsPlugins->nbPlugins(); for (int i = 0; i < pluginCount; ++i) { RsPlugin *rsPlugin = rsPlugins->plugin(i); if (rsPlugin) { ToasterNotify *toasterNotify = rsPlugin->qt_toasterNotify(); if (toasterNotify) { toaster = toasterNotify->toasterItem(); continue; } } } } if (toaster) { /* init attributes */ toaster->widget->setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint); /* add toaster to waiting list */ //QMutexLocker lock(&waitingToasterMutex); waitingToasterList.push_back(toaster); } if (rsNotify->NotifySysMessage(sysid, type, title, msg)) { /* make a warning message */ switch(type) { case RS_SYS_ERROR: QMessageBox::critical(MainWindow::getInstance(), QString::fromUtf8(title.c_str()), QString::fromUtf8(msg.c_str())); break; case RS_SYS_WARNING: QMessageBox::warning(MainWindow::getInstance(), QString::fromUtf8(title.c_str()), QString::fromUtf8(msg.c_str())); break; default: case RS_SYS_INFO: QMessageBox::information(MainWindow::getInstance(), QString::fromUtf8(title.c_str()), QString::fromUtf8(msg.c_str())); break; } } if (rsNotify->NotifyLogMessage(sysid, type, title, msg)) { /* make a log message */ std::string logMesString = title + " " + msg; switch(type) { case RS_SYS_ERROR: case RS_SYS_WARNING: case RS_SYS_INFO: emit logInfoChanged(QString::fromUtf8(logMesString.c_str())); } } } /* Now start the waiting toasters */ startWaitingToasters(); }