int irc_recv_mode(void *data) { struct irc_msgdata *msgdata = (struct irc_msgdata *) data; char *params[3]; int pnum; char *target, *mode_str, *param; int mode = msgdata->clientdata->chanmode; params[2] = NULL; struct ircflag chan_flags[] = { {'p', chan_priv}, {'s', chan_secret}, {'i', chan_invite}, {'t', chan_topiclock}, {'n', chan_nooutside}, {'m', chan_moderated}, IRCFLAGS_END }; pnum = irc_parse_paramlist(msgdata->msg, params, 3); target = params[0]; mode_str = params[1]; param = params[2] ? params[2] : ""; if (pnum >= 2 && (target[0] == '#' || target[0] == '&') && strncmp(target, msgdata->clientdata->chan, MAX_CHAN_LEN) == 0) { irc_flagparse(mode_str, &mode, chan_flags); setTopicProtect(mode & chan_topiclock, TRUE); setExternMsg(mode & chan_nooutside, TRUE); setSecret(mode & chan_secret, TRUE); setGuests(mode & chan_invite, TRUE); setPrivate(mode & chan_priv, TRUE); setModerated(mode & chan_moderated, TRUE); messageText("Channel mode modified: %s %s", mode_str, param); msgdata->clientdata->chanmode = mode; } else { messageText("User %s modified its mode: %s %s", target, mode_str, param); } return OK; }
void MsgViewBase::addMessage(Message *msg) { unsigned n = paragraphs() - 1; append(messageText(msg)); if (!CorePlugin::m_plugin->getOwnColors()) setBackground(n); if (!m_selectStr.isEmpty()){ bool bStart = false; for (; n < (unsigned)paragraphs(); n++){ QString s = text(n); if (s.find(MSG_HREF) >= 0){ bStart = true; continue; } if (bStart) break; } if (n < (unsigned)paragraphs()){ int savePara; int saveIndex; getCursorPosition(&savePara, &saveIndex); int para = n; int index = 0; while (find(m_selectStr, false, false, true, ¶, &index)){ setSelection(para, index, para, index + m_selectStr.length(), ++m_nSelection); setSelectionAttributes(m_nSelection, colorGroup().highlight(), true); index += m_selectStr.length(); } setCursorPosition(savePara, saveIndex); } } sync(); }
/******************************************************************************* * Presenta un mensaje protegido por semaforos al usuario. * * * * Parámetros: * * -Nombre de usuario. * -Mensaje. * -Tipo de mensaje. * -Proceso que llama. * * * Retorno: * * -void * * * *******************************************************************************/ void interfaceText(char *username, char *message, int type, int main_thread){ if(!main_thread){ gdk_threads_enter(); } switch(type){ case MSG_TEXT: messageText(message); break; case ERROR_TEXT: errorText(message); break; case PRIVATE_TEXT: privateText(username, message); break; case PUBLIC_TEXT: publicText(username, message); break; default: break; } if(!main_thread){ gdk_threads_leave(); } }
int irc_recv_nick(void *data) { struct irc_msgdata *msgdata = (struct irc_msgdata *) data; char prefix[MAX_NICK_LEN + 1]; char *params[1]; irc_get_prefix(msgdata->msg, prefix, MAX_NICK_LEN + 1); if (irc_parse_paramlist(msgdata->msg, params, 1) != 1) { slog(LOG_ERR, "Mensaje NICK mal formado: %s", msgdata->msg); return OK; } messageText("%s cambió su apodo a %s", prefix, params[0]); if (!strncmp(prefix, msgdata->clientdata->nick, MAX_NICK_LEN)) { msgdata->clientdata->connected = 1; strncpy(msgdata->clientdata->nick, params[0], MAX_NICK_LEN); setApodo(params[0]); saveUserSettings(params[0], getNombre(), getNombreReal()); } return OK; }
int irc_recv_who(void *data) { struct irc_msgdata *msgdata = (struct irc_msgdata *) data; char *msg = msgdata->msg; char *host; char *params[8]; int pnum; uint32_t ip; pnum = irc_parse_paramlist(msg, params, 8); if (pnum != 8) { slog(LOG_WARNING, "Mensaje RPL_WHO inválido: %s", msg); return OK; } messageText("WHO %s (%s/%s): conectado desde %s a %s", params[5], params[2], params[7], params[3], params[4]); if (!strncmp(msgdata->clientdata->nick, params[5], MAX_NICK_LEN)) /* Nuestro usuario */ { host = params[3]; if (resolve_ip4(host, &ip) != OK) { slog(LOG_WARNING, "No se ha podido resolver %s", host); } else { msgdata->clientdata->client_ip = ip; slog(LOG_INFO, "Guardada IP del cliente: %s", host); } } return OK; }
void messageText(int type, int stream, int indentNext, char *msg, int subline, const int *indexes) { int i; int len; printf("%-17s | ", (subline || (lastStream == stream && level[stream] > 0)) ? "|" : LOG_STREAM_NAME[stream]); printf("%-7s | ", (subline || (lastStream == stream && lastType[stream] == type && level[stream] > 0)) ? "|" : LOG_TYPE_DESC[type]); lastType[stream] = type; lastStream = stream; for(i=0; i<level[stream]; ++i) printf("| "); for(i=0; msg[i]; i++) { if(msg[i] == '\n') { msg[i] = '\0'; printf("%s\n", msg); if (msg[i+1]) { messageText(type, stream, 0, &msg[i+1], 1, indexes); } return; } } len = strlen(msg); if (len>0 && msg[len-1]=='\n') { printf("%s", msg); } else { printf("%s\n", msg); } fflush(NULL); if (indentNext) level[stream]++; }
void BitcoinGUI::incomingMessage(const QModelIndex & parent, int start, int end) { if(!messageModel) return; MessageModel *mm = messageModel; if (mm->index(start, MessageModel::TypeInt, parent).data().toInt() == MessageTableEntry::Received) { QString sent_datetime = mm->index(start, MessageModel::ReceivedDateTime, parent).data().toString(); QString from_address = mm->index(start, MessageModel::FromAddress, parent).data().toString(); QString to_address = mm->index(start, MessageModel::ToAddress, parent).data().toString(); QString message = mm->index(start, MessageModel::Message, parent).data().toString(); QTextDocument html; html.setHtml(message); QString messageText(html.toPlainText()); notificator->notify(Notificator::Information, tr("Incoming Message"), tr("Date: %1\n" "From Address: %2\n" "To Address: %3\n" "Message: %4\n") .arg(sent_datetime) .arg(from_address) .arg(to_address) .arg(messageText)); }; }
int irc_recv_join(void *data) { struct irc_msgdata *msgdata = (struct irc_msgdata *) data; char user[MAX_NICK_LEN + 1]; char *params[1]; if (irc_get_prefix(msgdata->msg, user, MAX_NICK_LEN + 1) != OK || irc_parse_paramlist(msgdata->msg, params, 1) != 1) { slog(LOG_ERR, "Mensaje JOIN mal formado: %s", msgdata->msg); return OK; } if (!strncmp(user, msgdata->clientdata->nick, MAX_NICK_LEN)) { if (msgdata->clientdata->in_channel) irc_send_response(msgdata, "PART %s", msgdata->clientdata->chan); msgdata->clientdata->in_channel = 1; enableChanMods(); strncpy(msgdata->clientdata->chan, params[0], MAX_CHAN_LEN); } messageText("%s ha entrado en el canal \"%s\"", user, params[0]); return OK; }
void ZLGtkProgressDialog::run(ZLRunnable &runnable) { while (gtk_events_pending()) { gtk_main_iteration(); } GtkWindow *mainWindow = GTK_WINDOW(gtk_window_new(GTK_WINDOW_POPUP)); gtk_window_set_accept_focus(mainWindow, FALSE); myLabel = gtk_label_new(messageText().c_str()); gtk_misc_set_padding(GTK_MISC(myLabel), 10, 10); // something nice? gtk_container_add(GTK_CONTAINER(mainWindow), myLabel); gtk_widget_show_all(GTK_WIDGET(mainWindow)); GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); if (myParent != 0) { gdk_window_set_cursor(GTK_WIDGET(myParent)->window, cursor); } gdk_window_set_cursor(GTK_WIDGET(mainWindow)->window, cursor); gdk_cursor_unref(cursor); int x, y, w, h; if (myParent != 0) { gtk_window_get_position(myParent, &x, &y); gtk_window_get_size(myParent, &w, &h); x += w / 2; y += h / 2; } else { GdkWindow *root = gdk_screen_get_root_window(gdk_screen_get_default()); gdk_window_get_geometry(root, &x, &y, &w, &h, 0); x += w / 2; y += h / 2; } gtk_window_get_size(mainWindow, &w, &h); x -= w / 2; y -= h / 2; gtk_window_move(mainWindow, x, y); while (gtk_events_pending()) { gtk_main_iteration(); } if (myParent != 0) { gtk_widget_queue_draw(GTK_WIDGET(myParent)); } while (gtk_events_pending()) { gtk_main_iteration(); } runnable.run(); myLabel = 0; if (myParent != 0) { gdk_window_set_cursor(GTK_WIDGET(myParent)->window, 0); } gtk_widget_destroy(GTK_WIDGET(mainWindow)); }
void disconnectClient(const char* bye_msg) { if(!bye_msg) bye_msg = "Redirc - bye!"; irc_send_message(snd_qid, client->serv_sock, "QUIT :%s", bye_msg); shutdown(client->serv_sock, 2); messageText("Desconexión del servidor."); setUserConnectionState(FALSE); }
void parse_pcall(struct irc_clientdata *cdata, char *text, char *source) { char *params[2]; int port; uint32_t ip; if (irc_parse_paramlist(text, params, 2) != 2) { slog(LOG_ERR, "Mensaje PRIVMSG/PCALL mal formado: %s", text); return; } ip = strtol(params[0], NULL, 10); if (ip == 0) { slog(LOG_ERR, "IP inválido: %s", params[0]); return; } port = strtol(params[1], NULL, 10); if (port == 0) { slog(LOG_ERR, "Puerto inválido: %s", params[1]); return; } if (cdata->call_status == call_none) { cdata->call_ip = ip; cdata->call_port = port; cdata->call_status = call_incoming; strncpy(cdata->call_user, source, MAX_NICK_LEN); messageText("Tienes una llamada de %s. Acéptala con /paccept.", source); } else { messageText("Has recibido una llamada de %s, pero sólo puedes tener una llamada a la vez.", source); } }
void MsgViewBase::addMessage(Message *msg, bool bUnread, bool bSync) { unsigned n = paragraphs(); if (n > 0) n--; append(messageText(msg, bUnread)); if (!CorePlugin::m_plugin->getOwnColors()) setBackground(n); if (bSync) sync(n); }
void MsgViewBase::reload() { QString t; vector<Msg_Id> msgs; unsigned i; for (i = 0; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; Msg_Id id; id.id = messageId(s.left(n), client); id.client = client; unsigned nn; for (nn = 0; nn < msgs.size(); nn++){ if ((msgs[nn].id == id.id) && (msgs[nn].client == id.client)) break; } if (nn >= msgs.size()) msgs.push_back(id); } for (i = 0; i < msgs.size(); i++){ Message *msg = History::load(msgs[i].id, msgs[i].client.c_str(), m_id); if (msg == NULL) continue; t += messageText(msg, false); delete msg; } QPoint p = QPoint(0, height()); p = mapToGlobal(p); p = viewport()->mapFromGlobal(p); int x, y; viewportToContents(p.x(), p.y(), x, y); int para; int pos = charAt(QPoint(x, y), ¶); setText(t); if (!CorePlugin::m_plugin->getOwnColors()) setBackground(0); if (pos == -1){ scrollToBottom(); }else{ setCursorPosition(para, pos); ensureCursorVisible(); } }
int irc_recv_topic(void *data) { struct irc_msgdata *msgdata = (struct irc_msgdata *) data; char *params[3]; if (irc_parse_paramlist(msgdata->msg, params, 3) < 3) { slog(LOG_ERR, "Respuesta RPL_TOPIC mal formada: %s", msgdata->msg); return OK; } messageText("El tema del canal \"%s\" es : %s", params[1], params[2]); return OK; }
void parse_pclose(struct irc_clientdata *cdata, char *text, char *source) { if (cdata->call_status != call_none) { messageText("El usuario remoto ha terminado la llamada."); if(cdata->call_status == call_outgoing) { close(cdata->call_socket); signal(SIGALRM, SIG_IGN); } else if(cdata->call_status == call_running) { call_stop(&(cdata->call_info)); } cdata->call_status = call_none; } }
int irc_recv_quit(void *data) { struct irc_msgdata *msgdata = (struct irc_msgdata *) data; char prefix[MAX_NICK_LEN + 1]; char *params[1]; irc_get_prefix(msgdata->msg, prefix, MAX_NICK_LEN + 1); if (irc_parse_paramlist(msgdata->msg, params, 1) != 1) { slog(LOG_ERR, "Mensaje QUIT mal formado: %s", msgdata->msg); return OK; } messageText("%s ha salido del canal: %s", prefix, params[0]); if (!strncmp(prefix, msgdata->clientdata->nick, MAX_NICK_LEN)) msgdata->clientdata->connected = 0; return OK; }
void parse_paccept(struct irc_clientdata *cdata, char *text, char *source) { char *params[2]; int port; uint32_t ip; if (cdata->call_status != call_outgoing) { slog(LOG_WARNING, "Hemos recibido un mensaje PACCEPT pero no hay llamadas pendientes."); return; } if (irc_parse_paramlist(text, params, 2) != 2) { slog(LOG_ERR, "Mensaje PRIVMSG/PACCEPT mal formado: %s", text); return; } ip = strtol(params[0], NULL, 10); if (ip == 0) { slog(LOG_ERR, "IP inválido: %s", params[0]); return; } port = strtol(params[1], NULL, 10); if (port == 0) { slog(LOG_ERR, "Puerto inválido: %s", params[1]); return; } signal(SIGALRM, SIG_IGN); spawn_call_manager_thread(&(cdata->call_info), ip, port, cdata->call_socket, VC_FORMAT, VC_CHANNELS, VC_CHUNK_TIME_MS); cdata->call_status = call_running; messageText("Llamada aceptada."); }
MsgView::MsgView(QWidget *parent, unsigned id) : MsgViewBase(parent, NULL, id) { int nCopy = CorePlugin::m_plugin->getCopyMessages(); unsigned nUnread = 0; for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if (m.contact == m_id) nUnread++; } if (nCopy || nUnread){ QString t = text(); HistoryIterator it(m_id); it.end(); while ((nCopy > 0) || nUnread){ Message *msg = --it; if (msg == NULL) break; t = messageText(msg, false) + t; nCopy--; if (nUnread == 0) continue; for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){ msg_id &m = (*it); if ((m.contact == msg->contact()) && (m.id == msg->id()) && (m.client == msg->client())){ nUnread--; break; } } } setText(t); if (!CorePlugin::m_plugin->getOwnColors()) setBackground(0); } scrollToBottom(); QTimer::singleShot(0, this, SLOT(init())); }
int irc_recv_part(void *data) { struct irc_msgdata *msgdata = (struct irc_msgdata *) data; char user[MAX_NICK_LEN + 1]; char *params[1]; if (irc_get_prefix(msgdata->msg, user, MAX_NICK_LEN + 1) != OK || irc_parse_paramlist(msgdata->msg, params, 1) != 1) { slog(LOG_ERR, "Mensaje PART mal formado: %s", msgdata->msg); return OK; } if (!strncmp(user, msgdata->clientdata->nick, MAX_NICK_LEN) && !strncmp(msgdata->clientdata->chan, params[0], MAX_CHAN_LEN)) { msgdata->clientdata->in_channel = 0; disableChanMods(); } messageText("%s ha salido del canal \"%s\"", user, params[0]); return OK; }
void QtChatWindow::dropEvent(QDropEvent *event) { if (fileTransferEnabled_ == Yes && event->mimeData()->hasUrls()) { if (event->mimeData()->urls().size() == 1) { onSendFileRequest(Q2PSTRING(event->mimeData()->urls().at(0).toLocalFile())); } else { std::string messageText(Q2PSTRING(tr("Sending of multiple files at once isn't supported at this time."))); ChatMessage message; message.append(boost::make_shared<ChatTextMessagePart>(messageText)); addSystemMessage(message, DefaultDirection); } } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) { QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list"); QDataStream dataStream(&dataBytes, QIODevice::ReadOnly); std::vector<JID> invites; while (!dataStream.atEnd()) { QString jidString; dataStream >> jidString; invites.push_back(Q2PSTRING(jidString)); } onInviteToChat(invites); }
void MsgViewBase::update() { if (m_updated.empty()) return; unsigned i; for (i = 0; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; unsigned id = messageId(s.left(n), client); list<Msg_Id>::iterator it; for (it = m_updated.begin(); it != m_updated.end(); ++it){ if (((*it).id == id) && ((*it).client == client)) break; } if (it != m_updated.end()) break; } m_updated.clear(); if (i >= (unsigned)paragraphs()) return; int x = contentsX(); int y = contentsY(); viewport()->setUpdatesEnabled(false); unsigned start = i; list<Msg_Id> msgs; for (; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; unsigned id = messageId(s.left(n), client); list<Msg_Id>::iterator it; for (it = msgs.begin(); it != msgs.end(); ++it){ if (((*it).id == id) && ((*it).client == client)) break; } if (it != msgs.end()) continue; Msg_Id m_id; m_id.id = id; m_id.client = client; msgs.push_back(m_id); } int paraFrom, indexFrom; int paraTo, indexTo; getSelection(¶From, &indexFrom, ¶To, &indexTo); setReadOnly(false); setSelection(start, 0, paragraphs() - 1, 0xFFFF, 0); removeSelectedText(); setReadOnly(true); QString text; for (list<Msg_Id>::iterator it = msgs.begin(); it != msgs.end(); ++it){ Message *msg = History::load((*it).id, (*it).client.c_str(), m_id); if (msg == NULL) continue; bool bUnread = false; for (list<msg_id>::iterator itu = CorePlugin::m_plugin->unread.begin(); itu != CorePlugin::m_plugin->unread.end(); ++itu){ msg_id &m = (*itu); if ((m.contact == msg->contact()) && (m.id == msg->id()) && (m.client == msg->client())){ bUnread = true; break; } } text += messageText(msg, bUnread); } viewport()->setUpdatesEnabled(true); append(text); if (!CorePlugin::m_plugin->getOwnColors()) setBackground(i); if ((paraFrom != paraTo) || (indexFrom != indexTo)) setSelection(paraFrom, indexFrom, paraTo, indexTo, 0); TextShow::sync(); setContentsPos(x, y); viewport()->repaint(); }
void ChatDlg::appendMessage(const Message &m, bool local) { // figure out the encryption state bool encChanged = false; bool encEnabled = false; if (lastWasEncrypted_ != m.wasEncrypted()) { encChanged = true; } lastWasEncrypted_ = m.wasEncrypted(); encEnabled = lastWasEncrypted_; if (encChanged) { if (encEnabled) { appendSysMsg(QString("<icon name=\"psi/cryptoYes\"> ") + tr("Encryption Enabled")); if (!local) { setPGPEnabled(true); } } else { appendSysMsg(QString("<icon name=\"psi/cryptoNo\"> ") + tr("Encryption Disabled")); if (!local) { setPGPEnabled(false); // enable warning warnSend_ = true; QTimer::singleShot(3000, this, SLOT(setWarnSendFalse())); } } } QString txt = messageText(m); ChatDlg::SpooledType spooledType = m.spooled() ? ChatDlg::Spooled_OfflineStorage : ChatDlg::Spooled_None; if (isEmoteMessage(m)) appendEmoteMessage(spooledType, m.timeStamp(), local, txt); else appendNormalMessage(spooledType, m.timeStamp(), local, txt); appendMessageFields(m); if (local) { deferredScroll(); } // if we're not active, notify the user by changing the title if (!isActiveTab()) { ++pending_; invalidateTab(); if (PsiOptions::instance()->getOption("options.ui.flash-windows").toBool()) { doFlash(true); } if (PsiOptions::instance()->getOption("options.ui.chat.raise-chat-windows-on-new-messages").toBool()) { if (isTabbed()) { TabDlg* tabSet = getManagingTabDlg(); tabSet->selectTab(this); ::bringToFront(tabSet, false); } else { ::bringToFront(this, false); } } } //else { // messagesRead(jid()); //} if (!local) { keepOpen_ = true; QTimer::singleShot(1000, this, SLOT(setKeepOpenFalse())); } }
QMailMessage EmailComposerInterface::message() const { QMailMessage mail; if( isEmpty() ) return mail; QList<AttachmentItem*> attachments = m_composer->addAttDialog()->attachedFiles(); QString messageText( m_composer->toPlainText() ); QMailMessageContentType type("text/plain; charset=UTF-8"); if(attachments.isEmpty()) { mail.setBody( QMailMessageBody::fromData( messageText, type, QMailMessageBody::Base64 ) ); } else { QMailMessagePart textPart; textPart.setBody(QMailMessageBody::fromData(messageText.toUtf8(), type, QMailMessageBody::Base64)); mail.setMultipartType(QMailMessagePartContainer::MultipartMixed); mail.appendPart(textPart); foreach (AttachmentItem* current, attachments) { const QContent& doc( current->document() ); QString fileName( doc.fileName() ); QFileInfo fi( fileName ); QString partName( fi.fileName() ); fileName = fi.absoluteFilePath(); QString content( doc.type() ); if (content.isEmpty()) content = QMimeType( fileName ).id(); QMailMessageContentType type( content.toLatin1() ); type.setName( partName.toLatin1() ); QMailMessageContentDisposition disposition( QMailMessageContentDisposition::Attachment ); disposition.setFilename( partName.toLatin1() ); QMailMessagePart part; if ((current->action() != QMailMessage::LinkToAttachments) || (fileName.startsWith(Qtopia::tempDir()))) { // This file is temporary - extract the data and create a part from that QFile dataFile(fileName); if (dataFile.open(QIODevice::ReadOnly)) { QDataStream in(&dataFile); part = QMailMessagePart::fromStream(in, disposition, type, QMailMessageBody::Base64, QMailMessageBody::RequiresEncoding); } else { qWarning() << "Unable to open temporary file:" << fileName; } } else { part = QMailMessagePart::fromFile(fileName, disposition, type, QMailMessageBody::Base64, QMailMessageBody::RequiresEncoding); } mail.appendPart(part); } } mail.setMessageType( QMailMessage::Email ); return mail; }
void MsgViewBase::update() { if (m_updated.empty()) return; unsigned i; for (i = 0; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; unsigned id = messageId(s.left(n), client); list<Msg_Id>::iterator it; for (it = m_updated.begin(); it != m_updated.end(); ++it){ if (((*it).id == id) && ((*it).client == client)) break; } if (it != m_updated.end()) break; } m_updated.clear(); if (i >= (unsigned)paragraphs()) return; QPoint p = QPoint(0, 0); p = mapToGlobal(p); p = viewport()->mapFromGlobal(p); int x, y; viewportToContents(p.x(), p.y(), x, y); int para; int pos = charAt(QPoint(x, y), ¶); p = QPoint(0, viewport()->height()); p = viewport()->mapToGlobal(p); p = mapFromGlobal(p); if (p.y() + 2 == height()) pos = -1; unsigned start = i; list<Msg_Id> msgs; for (; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; unsigned id = messageId(s.left(n), client); list<Msg_Id>::iterator it; for (it = msgs.begin(); it != msgs.end(); ++it){ if (((*it).id == id) && ((*it).client == client)) break; } if (it != msgs.end()) continue; Msg_Id m_id; m_id.id = id; m_id.client = client; msgs.push_back(m_id); } int paraFrom, indexFrom; int paraTo, indexTo; getSelection(¶From, &indexFrom, ¶To, &indexTo); setReadOnly(false); setSelection(start, 0, paragraphs() - 1, 0xFFFF); removeSelectedText(); setReadOnly(true); QString text; for (list<Msg_Id>::iterator it = msgs.begin(); it != msgs.end(); ++it){ Message *msg = History::load((*it).id, (*it).client.c_str(), m_id); if (msg == NULL) continue; bool bUnread = false; for (list<msg_id>::iterator itu = CorePlugin::m_plugin->unread.begin(); itu != CorePlugin::m_plugin->unread.end(); ++itu){ msg_id &m = (*itu); if ((m.contact == msg->contact()) && (m.id == msg->id()) && (m.client == msg->client())){ bUnread = true; break; } } text += messageText(msg, bUnread); } append(text); if (!CorePlugin::m_plugin->getOwnColors()) setBackground(0); if ((paraFrom != paraTo) || (indexFrom != indexTo)) setSelection(paraFrom, indexFrom, paraTo, indexTo); if (pos == -1){ scrollToBottom(); }else{ setCursorPosition(para, pos); ensureCursorVisible(); } }
void *MsgViewBase::processEvent(Event *e) { if (e->type() == EventMessageRead){ Message *msg = (Message*)(e->param()); if (msg->contact() != m_id) return NULL; for (unsigned i = 0; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_HREF); if (n < 0) continue; s = s.mid(n + strlen(MSG_HREF)); n = s.find("\""); if (n < 0) continue; s = s.left(n); unsigned id = atol(getToken(s, ',').latin1()); if (id != msg->id()) continue; getToken(s, ','); if (s != msg->client()) continue; int paraFrom, indexFrom; int paraTo, indexTo; getSelection(¶From, &indexFrom, ¶To, &indexTo); setSelection(i, 0, i, 0xFFFF); setBold(false); if ((paraFrom == -1) && (paraTo == -1)){ removeSelection(); scrollToBottom(); }else{ setSelection(paraFrom, indexFrom, paraTo, indexTo); } break; } return NULL; } if (e->type() == EventHistoryConfig){ unsigned id = (unsigned)(e->param()); if (id && (id != m_id)) return NULL; QString t; for (unsigned i = 0; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_HREF); if (n < 0) continue; s = s.mid(n + strlen(MSG_HREF)); n = s.find("\""); if (n < 0) continue; s = s.left(n); unsigned id = atol(getToken(s, ',').latin1()); getToken(s, ','); Message *msg = History::load(id, s.utf8(), m_id); if (msg == NULL) continue; t += messageText(msg); delete msg; } QPoint p = QPoint(0, height()); p = mapToGlobal(p); p = viewport()->mapFromGlobal(p); int x, y; viewportToContents(p.x(), p.y(), x, y); int para; int pos = charAt(QPoint(x, y), ¶); setText(t); setBackground(0); if (pos == -1){ scrollToBottom(); }else{ setCursorPosition(para, pos); ensureCursorVisible(); } } if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->param != this) || (cmd->menu_id != MenuMsgView)) return NULL; Message *msg; switch (cmd->id){ case CmdCopy: cmd->flags &= ~(COMMAND_DISABLED | COMMAND_CHECKED); if (!hasSelectedText()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdMsgOpen: msg = currentMessage(); if (msg){ unsigned type = msg->type(); delete msg; for (;;){ CommandDef *def = CorePlugin::m_plugin->messageTypes.find(type); if (def == NULL){ return NULL; } MessageDef *mdef = (MessageDef*)(def->param); if (mdef->base_type){ type = mdef->base_type; continue; } cmd->icon = def->icon; cmd->flags &= ~COMMAND_CHECKED; return e->param(); } } return NULL; case CmdMsgSpecial: msg = currentMessage(); if (msg){ Event eMenu(EventGetMenuDef, (void*)MenuMsgCommand); CommandsDef *cmdsMsg = (CommandsDef*)(eMenu.process()); unsigned n = 0; MessageDef *mdef = NULL; if (msg->getFlags() & MESSAGE_RECEIVED){ unsigned type = msg->type(); for (;;){ CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type); if (msgCmd == NULL) break; mdef = (MessageDef*)(msgCmd->param); if (mdef->base_type == 0) break; type = mdef->base_type; } } if (mdef && mdef->cmd){ for (const CommandDef *d = mdef->cmd; d->text; d++) n++; } { CommandsList it(*cmdsMsg, true); while (++it) n++; } if (n == 0) return NULL; n++; CommandDef *cmds = new CommandDef[n]; memset(cmds, 0, sizeof(CommandDef) * n); n = 0; if (mdef && mdef->cmd){ for (const CommandDef *d = mdef->cmd; d->text; d++){ cmds[n] = *d; cmds[n].id = CmdMsgSpecial + n; n++; } } CommandDef *c; CommandsList it(*cmdsMsg, true); while ((c = ++it) != NULL){ CommandDef cmd = *c; cmd.menu_id = MenuMsgCommand; cmd.param = msg; Event e(EventCheckState, &cmd); if (!e.process()) continue; cmd.flags &= ~COMMAND_CHECK_STATE; cmds[n++] = cmd; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; delete msg; return e->param(); } return NULL; } } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->param != this) || (cmd->menu_id != MenuMsgView)) return NULL; Message *msg; switch (cmd->id){ case CmdCopy: copy(); return e->param(); case CmdMsgOpen: msg = currentMessage(); if (msg){ Event eOpen(EventOpenMessage, msg); eOpen.process(); delete msg; return e->param(); } return NULL; default: msg = currentMessage(); if (msg){ if (cmd->id >= CmdMsgSpecial){ MessageDef *mdef = NULL; unsigned type = msg->type(); for (;;){ CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type); if (msgCmd == NULL) break; mdef = (MessageDef*)(msgCmd->param); if (mdef->base_type == 0) break; type = mdef->base_type; } if (mdef && mdef->cmd){ unsigned n = cmd->id - CmdMsgSpecial; for (const CommandDef *d = mdef->cmd; d->text; d++){ if (n-- == 0){ CommandDef cmd = *d; cmd.param = msg; Event eCmd(EventCommandExec, &cmd); eCmd.process(); return e->param(); } } } } Command c; c->id = cmd->id; c->menu_id = MenuMsgCommand; c->param = msg; Event e(EventCommandExec, c); void *res = e.process(); delete msg; return res; } return NULL; } } return NULL; }
/** * Exposed DLL entry point for custom action. * The function signature matches the calling convention used by Windows Installer. * * This function supports four policy stances with respect to a running IE process. * * - Allow reboot. * IE is running, so what? I'm willing to reboot after installation. * - Avoid reboot passively. * I don't want to affect any other running processes, but I don't want to reboot. I'll abort the installation. * - Avoid reboot actively. * I want to shut down IE in order to avoid a reboot. * I'll do it manually when the time is right. * - Avoid reboot automatically. * I want to shut down IE automatically in order to avoid a reboot. * * In a silent installation, the default stance is "allow reboot", which is to say, to act like most installers. * In an interactive installation, the stance is gathered from the user through dialog boxes. * If the MSI property AVOIDREBOOT is set to one of the values NO, PASSIVE, ACTIVE, or AUTOMATIC, the policy is set accordingly. * In a silent installation, this is the only way getting a stance other than the default. * In an interactive installation, AVOIDREBOOT skips the dialogs. * * \param[in] sessionHandle * Windows installer session handle * * \return * An integer interpreted as a custom action return value. * * \post * + The return value is one of the following: * - ERROR_INSTALL_USEREXIT if the user cancelled installation. * - ERROR_INSTALL_FAILURE if something unexpected happened, usually if the top level try-block caught an exception. * - ERROR_SUCCESS otherwise. * + The function performed at least one check that Internet Explorer was running. * + If ERROR_SUCCESS, the MSI property RUNNINGBROWSER is set and has one of the following values: * - 1 if Internet Explorer was running upon the last check. * - 0 otherwise. * \post * Note that this function cannot provide any assurance that Internet Explorer stays either stays running or stays not running. * * \sa * - MSDN [Custom Action Return Values](http://msdn.microsoft.com/en-us/library/aa368072%28v=vs.85%29.aspx) */ extern "C" UINT __stdcall AbpCloseIe(MSIHANDLE sessionHandle) { // Utility typedef to shorten the class name. typedef InstallerMessageBox IMB; /* * ImmediateSession cannot throw, so it can go outside the try-block. * It's needed in the catch-all block to write an error message to the log. */ ImmediateSession session(sessionHandle, "AbpCloseIe"); // The body of an entry point function must have a catch-all. try { // MSI property BROWSERRUNNING is one of the return values of this function. Property browserRunning(session, L"BROWSERRUNNING"); Property browserClosed(session, L"BROWSERCLOSED"); // Instantiation of ProcessCloser takes a snapshot. InternetExplorerCloser iec; /* * We take the short path through this function if neither IE nor engine is not running at the outset. */ if (!iec.IsRunning()) { browserRunning = L"0"; // The browser is not running. browserClosed = L"0"; // We didn't close the browser (and we couldn't have). session.Log("IE not running. No issue with reboot policy."); return ERROR_SUCCESS; } /* * As a (potentially) user-driven function, a state machine manages control flow. * The states are organized around the policy stances. */ enum PolicyState { // Non-terminal states notKnown, // We don't know the user's stance at all partKnown, // The user has indicated either ACTIVE or AUTOMATIC active, // Actively avoid reboot automatic, // Automatically avoid reboot // Terminal states success, abort, // Aliases for what would ordinarily be non-terminal states. // They're terminal because of implementation details. allow = success, // Allow reboot. passive = abort, // Passively avoid reboot, that is, don't try to close IE. }; PolicyState state; /* * Use the AVOIDREBOOT property, if present, to set an initial state. */ std::wstring avoidReboot = Property(session, L"AVOIDREBOOT"); std::transform(avoidReboot.begin(), avoidReboot.end(), avoidReboot.begin(), ::towupper); if (avoidReboot == L"") { state = notKnown; } else if (avoidReboot == L"NO") { state = allow; session.Log("Reboot allowed on command line."); } else if (avoidReboot == L"PASSIVE") { state = passive; session.Log("Reboot avoided on command line."); } else if (avoidReboot == L"ACTIVE") { state = active; } else if (avoidReboot == L"AUTOMATIC") { state = automatic; } else { // It's an error to specify an unrecognized value for AVOIDREBOOT. throw std::runtime_error("unrecognized value for AVOIDREBOOT"); } /* * When running as an update (see Updater.cpp), this installer receives the command line option "/qb", * which sets the UI level to "Basic UI". * When running as an initial install, we cannot expect what command line options this installer receives. */ /* * The UILevel property indicates whether we have the ability to put dialog boxes up. * Levels 2 (silent) and 3 (basic) do not have this ability. * Levels 4 (reduced) and 5 (full) do. * * MSDN [UILevel property](http://msdn.microsoft.com/en-us/library/windows/desktop/aa372096%28v=vs.85%29.aspx) */ std::wstring uilevel = Property(session, L"UILevel"); bool interactive; if (uilevel == L"5" || uilevel == L"4") { interactive = true; // Assert state is one of { notKnown, allow, passive, active, automatic } } else if (uilevel == L"3" || uilevel == L"2") { // Assert installer is running without user interaction. interactive = false; if (state == notKnown) { // Assert AVOIDREBOOT was not specified /* * This is where we specify default behavior for non-interactive operation. * The choice of "allow" makes it act like other installers, which is to make no effort to avoid a reboot after installation. */ state = allow; session.Log("Reboot allowed by default in non-interactive session."); } else if (state == active) { throw std::runtime_error("AVOIDREBOOT=ACTIVE in non-interative session is not consistent"); } // Assert state is one of {allow, passive, automatic} } else { throw std::runtime_error("unrecognized value for UILevel"); } /* * Now that preliminaries are over, we set up the accessors for UI text. * We only use the object 'messageText' for interactive sessions, but it's cheap to set up and a hassle to conditionalize. * * The key "close_ie" is the component name within the file "close_ie.wxi" that defines rows in the localization table. * The identifiers for the messageText.text() function are defined within that file. */ InstallationDatabase db(session); CustomMessageText messageText(db, L"close_ie"); /* * State machine: Loop through non-terminal states. * * Loop invariant: IE was running at last check, that is, iec.IsRunning() would return true. */ while (state <= automatic) // "automatic" is the non-terminal state with the highest value { switch (state) { case notKnown: /* * Precondition: interactive session * * Ask the user "Would you like to close IE and avoid reboot?" * Yes -> Close IE somehow. Goto partKnown. * No -> Install with reboot. Goto allow. * Cancel -> terminate installation. Goto abort. */ { int x = session.WriteMessage(IMB( messageText.Text(L"dialog_unknown"), IMB::Box::warning, IMB::ButtonSet::yesNoCancel, IMB::DefaultButton::three)); switch (x) { case IDYES: state = partKnown; break; case IDNO: state = allow; session.Log("User chose to allow reboot"); break; case IDCANCEL: state = abort; session.Log("User cancelled installation"); break; default: throw UnexpectedReturnValueFromMessageBox(); } } break; case partKnown: /* * Precondition: interactive session * * Ask the user "Would you like the installer to close IE for you?" * Yes -> Goto automatic * No -> Goto active * Cancel -> Goto notKnown */ { int x = session.WriteMessage(IMB( messageText.Text(L"dialog_part_known"), IMB::Box::warning, IMB::ButtonSet::yesNoCancel, IMB::DefaultButton::three)); switch (x) { case IDYES: state = automatic; break; case IDNO: state = active; break; case IDCANCEL: state = notKnown; break; default: throw UnexpectedReturnValueFromMessageBox(); } } break; case active: /* * Precondition: interactive session * * IE is no longer running -> Goto success * IE is still running -> * Ask the user to close IE manually * OK -> re-enter this state * Cancel -> Goto notKnown */ { int x = session.WriteMessage(IMB( messageText.Text(L"dialog_active_retry"), IMB::Box::warning, IMB::ButtonSet::okCancel, IMB::DefaultButton::one)); switch (x) { case IDOK: /* * Refresh our knowledge of whether IE is running. * If it is, we display the dialog again. The state doesn't change, so we just iterate again. * If it's not, then the user has closed IE and we're done. */ iec.Refresh(); if (!iec.IsRunning()) { state = success; session.Log("User shut down IE manually."); } break; case IDCANCEL: state = notKnown; break; default: throw UnexpectedReturnValueFromMessageBox(); } } break; case automatic: /* * Close all known IE instances. * Unlike other cases, this state starts with an action and not a user query. * We first shut down IE, or at least attempt to. * * Succeeded -> Goto success * Failed && interactive -> * Ask user if they would like to try again * Retry -> re-enter this state * Cancel -> Goto notKnown * Failed && not interactive -> Goto abort */ { bool ieWasClosed = iec.ShutDown(session); if (iec.IsRunning()) { session.Log("Attempt to shut down IE automatically failed."); if (interactive) { // Assert Interactive session and IE did not shut down. int x = session.WriteMessage(IMB( messageText.Text(L"dialog_automatic_retry"), IMB::Box::warning, IMB::ButtonSet::retryCancel, IMB::DefaultButton::one)); switch (x) { case IDRETRY: // Don't change the state. Iterate again. break; case IDCANCEL: state = notKnown; break; default: throw UnexpectedReturnValueFromMessageBox(); } } else { // Assert Non-interactive session and IE did not shut down. state = abort; session.Log("Failed to shut down IE automatically."); } } else { // Assert IE is not running, so ShutDown() succeeded. state = success; session.Log("Automatically shut down IE."); } } break; } } /* * State machine: Actions for terminal states. */ switch (state) { case success: if (iec.IsRunning()) { browserRunning = L"1"; browserClosed = L"0"; } else { browserRunning = L"0"; browserClosed = L"1"; } return ERROR_SUCCESS; break; case abort: return ERROR_INSTALL_USEREXIT; break; } } catch (std::exception& e) { session.LogNoexcept("terminated by exception: " + std::string(e.what())); return ERROR_INSTALL_FAILURE; } catch (...) { session.LogNoexcept("terminated by unknown exception"); return ERROR_INSTALL_FAILURE; } // Should be unreachable. return ERROR_INSTALL_FAILURE; }
int OculusRoomTinyApp::OnStartup(const char* args) { OVR_UNUSED(args); // *** Oculus HMD & Sensor Initialization // Create DeviceManager and first available HMDDevice from it. // Sensor object is created from the HMD, to ensure that it is on the // correct device. pManager = *DeviceManager::Create(); // We'll handle it's messages in this case. pManager->SetMessageHandler(this); int detectionResult = IDCONTINUE; const char* detectionMessage; do { // Release Sensor/HMD in case this is a retry. pSensor.Clear(); pHMD.Clear(); RenderParams.MonitorName.Clear(); pHMD = *pManager->EnumerateDevices<HMDDevice>().CreateDevice(); if (pHMD) { pSensor = *pHMD->GetSensor(); // This will initialize HMDInfo with information about configured IPD, // screen size and other variables needed for correct projection. // We pass HMD DisplayDeviceName into the renderer to select the // correct monitor in full-screen mode. if (pHMD->GetDeviceInfo(&HMDInfo)) { RenderParams.MonitorName = HMDInfo.DisplayDeviceName; RenderParams.DisplayId = HMDInfo.DisplayId; SConfig.SetHMDInfo(HMDInfo); } } else { // If we didn't detect an HMD, try to create the sensor directly. // This is useful for debugging sensor interaction; it is not needed in // a shipping app. pSensor = *pManager->EnumerateDevices<SensorDevice>().CreateDevice(); } // If there was a problem detecting the Rift, display appropriate message. detectionResult = IDCONTINUE; if (!pHMD && !pSensor) detectionMessage = "Oculus Rift not detected."; else if (!pHMD) detectionMessage = "Oculus Sensor detected; HMD Display not detected."; else if (!pSensor) detectionMessage = "Oculus HMD Display detected; Sensor not detected."; else if (HMDInfo.DisplayDeviceName[0] == '\0') detectionMessage = "Oculus Sensor detected; HMD display EDID not detected."; else detectionMessage = 0; if (detectionMessage) { String messageText(detectionMessage); messageText += "\n\n" "Press 'Try Again' to run retry detection.\n" "Press 'Continue' to run full-screen anyway."; detectionResult = ::MessageBoxA(0, messageText.ToCStr(), "Oculus Rift Detection", MB_CANCELTRYCONTINUE|MB_ICONWARNING); if (detectionResult == IDCANCEL) return 1; } } while (detectionResult != IDCONTINUE); if (HMDInfo.HResolution > 0) { Width = HMDInfo.HResolution; Height = HMDInfo.VResolution; } if (!setupWindow()) return 1; if (pSensor) { // We need to attach sensor to SensorFusion object for it to receive // body frame messages and update orientation. SFusion.GetOrientation() // is used in OnIdle() to orient the view. SFusion.AttachToSensor(pSensor); SFusion.SetDelegateMessageHandler(this); } // *** Initialize Rendering // Enable multi-sampling by default. RenderParams.Multisample = 4; RenderParams.Fullscreen = true; // Setup Graphics. pRender = *RenderTiny::D3D10::RenderDevice::CreateDevice(RenderParams, (void*)hWnd); if (!pRender) return 1; // *** Configure Stereo settings. SConfig.SetFullViewport(Viewport(0,0, Width, Height)); SConfig.SetStereoMode(Stereo_LeftRight_Multipass); // Configure proper Distortion Fit. // For 7" screen, fit to touch left side of the view, leaving a bit of invisible // screen on the top (saves on rendering cost). // For smaller screens (5.5"), fit to the top. if (HMDInfo.HScreenSize > 0.0f) { if (HMDInfo.HScreenSize > 0.140f) // 7" SConfig.SetDistortionFitPointVP(-1.0f, 0.0f); else SConfig.SetDistortionFitPointVP(0.0f, 1.0f); } pRender->SetSceneRenderScale(SConfig.GetDistortionScale()); SConfig.Set2DAreaFov(DegreeToRad(85.0f)); // *** Populate Room Scene // This creates lights and models. PopulateRoomScene(&Scene, pRender); LastUpdate = GetAppTime(); return 0; }
void connectToServer(const char *server, const char* port) { char *nick = getApodo(); char *user = getNombre(); char *name = getNombreReal(); int sock; const char *err; char addr_str[100]; int retval; struct serv_info serv; if (!server || strlen(server) == 0) { errorText("Error: servidor inválido."); return; } if (!port || strlen(port) == 0) { errorText("Error: puerto inválido."); return; } if (!nick || !user || !name || strlen(nick) == 0 || strlen(user) == 0 || strlen(name) == 0) { errorWindow("Rellene los datos de nombre/usuario/apodo"); return; } if(client->connected) disconnectClient(NULL); messageText("Conectando con %s...", server); retval = client_connect_to(server, port, addr_str, 100); if (retval == ERR_SYS) err = strerror(errno); else if (retval == ERR_AIR) err = "no se ha podido resolver la dirección"; else if (retval == ERR_NOTFOUND) err = "no se ha podido conectar."; else err = "error desconocido."; if (retval <= 0) { errorText("Error resolviendo %s: %s", server, err); return; } sock = retval; if (send_message(rcv_sockcomm, &sock, sizeof(int)) == ERR_SOCK) { errorText("Error al configurar la nueva conexión: %s", strerror(errno)); close(sock); return; } irc_send_message(snd_qid, sock, "NICK %s", getApodo()); irc_send_message(snd_qid, sock, "USER %s %s %s :%s", getNombre(), "0", "*", getNombreReal()); client->connected = 1; strncpy(client->nick, nick, MAX_NICK_LEN); client->serv_sock = sock; setUserConnectionState(TRUE); strncpy(serv.servname, server, SERV_NAMELEN); strncpy(serv.port, port, MAX_PORT_LEN); serv_save_connection(&serv); client->connected = 1; messageText("Conectado a %s", addr_str); saveUserSettings(nick, user, name); }
void Instrument::Message::report() const { information(messageText()); }
void printMessageText(JaslErrorMessage* jaslErrorMessage) { fprintf(stderr,"\nCaught: %s",messageText(jaslErrorMessage)); }