Date: Wed, 16 Oct 2013 21:55:40 +0000 (+0100)
Subject: LyX XMPP Chat
http://git.lyx.org/?p=developers%2Ftommaso%2Flyx.git;a=commitdiff_plain;h=9646b7553bb4a3916e8b99f9e2dc200e7d534dfb
LyX XMPP Chat
---
@@ -186,7 +190,8 @@ SOURCEFILESCORE = \
VCBackend.cpp \
version.cpp \
VSpace.cpp \
- WordList.cpp
+ WordList.cpp \
+ moc_BufferView.cpp
HEADERFILESCORE = \
Author.h \
@@ -316,7 +321,7 @@ endif
######################### Qt stuff ##############################
-MOCHEADER = Compare.h
+MOCHEADER = Compare.h BufferView.h
if INSTALL_WINDOWS
Why is BufferView suddenly moc'ed while it hasn't changed ?
diff --git a/src/frontends/qt4/GuiBuddies.cpp
b/src/frontends/qt4/GuiBuddies.cpp
new file mode 100644
index 0000000..138d162
--- /dev/null
+++ b/src/frontends/qt4/GuiBuddies.cpp
@@ -0,0 +1,284 @@
+/**
+ * \file GuiBuddies.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Tommaso Cucinotta
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiBuddies.h"
+#include "GuiChat.h"
+#include "LyXRC.h"
+
+#include "GuiApplication.h"
+#include "GuiView.h"
+#include "GuiWorkArea.h"
+#include "qt_helpers.h"
+#include "Language.h"
+#include <QWidget>
+#include <QInputDialog>
+#include <QLineEdit>
+
+#include "FuncRequest.h"
+#include "lyxfind.h"
+
+#include "frontends/alert.h"
+#include "DispatchResult.h"
+
+#include "support/debug.h"
+#include "support/filetools.h"
+#include "support/FileName.h"
+#include "support/gettext.h"
+#include "support/lassert.h"
+#include "support/lstrings.h"
+#include "support/Package.h"
+
+#include <qxmpp/QXmppMessage.h>
+#include <qxmpp/QXmppRosterManager.h>
+
The sorting of the include could be improved a bit.
+static string availStatusToText(QXmppPresence::AvailableStatusType s) {
+ static const char *texts[] = { "Online", "Away", "Extended Away", "Do
Not Disturb", "Buddies", "Invisible" };
+ LASSERT(s <= sizeof(texts) / sizeof(texts[0]), /**/);
+ return texts[s];
+}
+
+
+static string presenceTypeToText(QXmppPresence::Type t) {
+ static const char *texts[] = { "Error", "Available", "Unavailable",
"Subscribe", "Subscribed", "Unsubscribe", "Unsubscribed", "Probe" };
+ LASSERT(t <= sizeof(texts) / sizeof(texts[0]), /**/);
+ return texts[t];
+}
One of the reasons to nicely squash together commits within a series is
that I wouldn't start commenting on this part of the patch as it is removed
later on. Now, I don't know that and I might start reviewing irrelevant
parts.
+
+
+static QListWidgetItem *findInListWidget(QListWidget *p_list, const
QString &s) {
We use to write "QString const & s".
+ for (int i = 0; i < p_list->count(); ++i)
+ if (p_list->item(i)->text() == s)
+ return p_list->item(i);
+ return 0;
+}
+
Would it be an idea to use QListWidget::findItems() ?
+void GuiBuddiesWidget::onStateSelected(const QString & qs)
+{
+ QXmppPresence p;
+ string s = fromqstr(qs);
+ if (s == "Available")
+ p.setAvailableStatusType(QXmppPresence::Online);
+ else if (s == "Away")
+ p.setAvailableStatusType(QXmppPresence::Away);
+ else if (s == "Do Not Disturb")
+ p.setAvailableStatusType(QXmppPresence::DND);
+ lyxerr << "Setting ";
+ dumpPres(p);
+ theChatMessenger()->setClientPresence(p);
+}
Why converting from QString to string before ?
diff --git a/src/frontends/qt4/GuiBuddies.h b/src/frontends/qt4/GuiBuddies.h
new file mode 100644
index 0000000..d85f131
--- /dev/null
+++ b/src/frontends/qt4/GuiBuddies.h
@@ -0,0 +1,105 @@
[..]
+#ifndef QGUIBUDDIES_H
+#define QGUIBUDDIES_H
QGUIBUDDIES_H ?
+
+#undef QT_NO_KEYWORDS
Why ?
+
+void GuiChatWidget::onMessageReceived(string const & from, string const &
s)
+{
+ printf("Received %lu bytes: %s\n", s.size(), s.c_str());
printf ?
diff --git a/src/frontends/qt4/GuiChat.h b/src/frontends/qt4/GuiChat.h
new file mode 100644
index 0000000..724815a
--- /dev/null
+++ b/src/frontends/qt4/GuiChat.h
@@ -0,0 +1,109 @@
+// -*- C++ -*-
+/**
+ * \file Chat.h
Chat.h ?
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Tommaso Cucinotta
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef QGUICHAT_H
+#define QGUICHAT_H
QGUICHAT_H ?
+
+#undef QT_NO_KEYWORDS
Why ?
diff --git a/src/frontends/qt4/GuiChatMessenger.h
b/src/frontends/qt4/GuiChatMessenger.h
new file mode 100644
index 0000000..f8e2b3c
--- /dev/null
+++ b/src/frontends/qt4/GuiChatMessenger.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+/**
+ * \file Chat.h
Chat.h ?
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Tommaso Cucinotta
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef QGUICHATMESSENGER_H
+#define QGUICHATMESSENGER_H
QGUICHATMESSENGER_H?
+
+#undef QT_NO_KEYWORDS
+
Why ?
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index a7cbbe4..f397da7 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -1734,7 +1734,9 @@ bool GuiView::getStatus(FuncRequest const & cmd,
FuncStatus & flag)
|| name == "prefs"
|| name == "texinfo"
|| name == "progress"
- || name == "compare";
+ || name == "compare"
+ || name == "chat"
+ || name == "chat-bar";
else if (name == "print")
enable = doc_buffer->params().isExportable("dvi")
&& lyxrc.print_command != "none";
@@ -3957,7 +3959,7 @@ namespace {
char const * const dialognames[] = {
"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
-"citation", "compare", "comparehistory", "document", "errorlist", "ert",
+"chat", "chat-bar", "citation", "compare", "comparehistory", "document",
"errorlist", "ert",
"external", "file", "findreplace", "findreplaceadv", "float", "graphics",
"href", "include", "index", "index_print", "info", "listings", "label",
"line",
"log", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature",
@@ -4144,6 +4146,8 @@ Dialog * createGuiAbout(GuiView & lv);
Dialog * createGuiBibtex(GuiView & lv);
Dialog * createGuiChanges(GuiView & lv);
Dialog * createGuiCharacter(GuiView & lv);
+Dialog * createGuiChat(GuiView & lv);
+Dialog * createGuiBuddies(GuiView & lv);
Dialog * createGuiCitation(GuiView & lv);
Dialog * createGuiCompare(GuiView & lv);
Dialog * createGuiCompareHistory(GuiView & lv);
@@ -4192,10 +4196,14 @@ Dialog * GuiView::build(string const & name)
return createGuiAbout(*this);
if (name == "bibtex")
return createGuiBibtex(*this);
+ if (name == "chat")
+ return createGuiBuddies(*this);
if (name == "changes")
return createGuiChanges(*this);
if (name == "character")
return createGuiCharacter(*this);
+ if (name == "chat-bar")
+ return createGuiChat(*this);
if (name == "citation")
return createGuiCitation(*this);
if (name == "compare")
"chat" refers to GuiBuddies, and "chat-bar" refers to GuiChat ? This looks
a bit confusing.
diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h
index 17e60df..4e563d2 100644
--- a/src/frontends/qt4/GuiView.h
+++ b/src/frontends/qt4/GuiView.h
void hideDialog(std::string const & name, Inset * inset);
///
void disconnectDialog(std::string const & name);
+ ///
+ Dialog * findOrBuild(std::string const & name, bool hide_it);
/// Saves the layout and geometry of the window
/// Is the dialog currently visible?
bool isDialogVisible(std::string const & name) const;
///
- Dialog * findOrBuild(std::string const & name, bool hide_it);
- ///
Dialog * build(std::string const & name);
///
bool reloadBuffer(Buffer & buffer);
Why ? Please respect if a function is private to keep it private. GuiView
manages all dialogs, and widgets.
Can't you use doShowDialog ? This avoids handling the focus yourself etc.
Vincent