More Code Cleanup
authorMarcus Eggenberger <egs@quassel-irc.org>
Sun, 3 Feb 2008 14:22:34 +0000 (14:22 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sun, 3 Feb 2008 14:22:34 +0000 (14:22 +0000)
- CTCP Replys are working now
- /query asdf opens now a new buffer
- highlights are now determined in the client

40 files changed:
src/client/networkmodel.cpp
src/common/message.h
src/core/SQL/SQLite/3/delete_backlog_by_uid.sql [moved from src/core/SQL/SQLite/2/delete_backlog_by_uid.sql with 100% similarity]
src/core/SQL/SQLite/3/delete_buffers_by_uid.sql [moved from src/core/SQL/SQLite/2/delete_buffers_by_uid.sql with 100% similarity]
src/core/SQL/SQLite/3/delete_networks_by_uid.sql [moved from src/core/SQL/SQLite/2/delete_networks_by_uid.sql with 100% similarity]
src/core/SQL/SQLite/3/delete_quasseluser.sql [moved from src/core/SQL/SQLite/2/delete_quasseluser.sql with 100% similarity]
src/core/SQL/SQLite/3/insert_buffer.sql [moved from src/core/SQL/SQLite/2/insert_buffer.sql with 100% similarity]
src/core/SQL/SQLite/3/insert_message.sql [moved from src/core/SQL/SQLite/2/insert_message.sql with 100% similarity]
src/core/SQL/SQLite/3/insert_network.sql [moved from src/core/SQL/SQLite/2/insert_network.sql with 100% similarity]
src/core/SQL/SQLite/3/insert_quasseluser.sql [moved from src/core/SQL/SQLite/2/insert_quasseluser.sql with 100% similarity]
src/core/SQL/SQLite/3/insert_sender.sql [moved from src/core/SQL/SQLite/2/insert_sender.sql with 100% similarity]
src/core/SQL/SQLite/3/select_authuser.sql [moved from src/core/SQL/SQLite/2/select_authuser.sql with 100% similarity]
src/core/SQL/SQLite/3/select_bufferByName.sql [moved from src/core/SQL/SQLite/2/select_bufferByName.sql with 100% similarity]
src/core/SQL/SQLite/3/select_buffers.sql [moved from src/core/SQL/SQLite/2/select_buffers.sql with 100% similarity]
src/core/SQL/SQLite/3/select_lastMessage.sql [moved from src/core/SQL/SQLite/2/select_lastMessage.sql with 100% similarity]
src/core/SQL/SQLite/3/select_messageRange.sql [moved from src/core/SQL/SQLite/2/select_messageRange.sql with 100% similarity]
src/core/SQL/SQLite/3/select_messages.sql [moved from src/core/SQL/SQLite/2/select_messages.sql with 100% similarity]
src/core/SQL/SQLite/3/select_messagesOffset.sql [moved from src/core/SQL/SQLite/2/select_messagesOffset.sql with 100% similarity]
src/core/SQL/SQLite/3/select_messagesSince.sql [moved from src/core/SQL/SQLite/2/select_messagesSince.sql with 100% similarity]
src/core/SQL/SQLite/3/select_messagesSinceOffset.sql [moved from src/core/SQL/SQLite/2/select_messagesSinceOffset.sql with 100% similarity]
src/core/SQL/SQLite/3/select_userid.sql [moved from src/core/SQL/SQLite/2/select_userid.sql with 100% similarity]
src/core/SQL/SQLite/3/setup_000_quasseluser.sql [moved from src/core/SQL/SQLite/2/setup_000_quasseluser.sql with 100% similarity]
src/core/SQL/SQLite/3/setup_010_sender.sql [moved from src/core/SQL/SQLite/2/setup_010_sender.sql with 100% similarity]
src/core/SQL/SQLite/3/setup_020_network.sql [moved from src/core/SQL/SQLite/2/setup_020_network.sql with 100% similarity]
src/core/SQL/SQLite/3/setup_040_buffer.sql [moved from src/core/SQL/SQLite/2/setup_040_buffer.sql with 100% similarity]
src/core/SQL/SQLite/3/setup_050_buffer_idx.sql [moved from src/core/SQL/SQLite/2/setup_050_buffer_idx.sql with 100% similarity]
src/core/SQL/SQLite/3/setup_060_backlog.sql [moved from src/core/SQL/SQLite/2/setup_060_backlog.sql with 100% similarity]
src/core/SQL/SQLite/3/setup_070_coreinfo.sql [moved from src/core/SQL/SQLite/2/setup_070_coreinfo.sql with 100% similarity]
src/core/SQL/SQLite/3/setup_080_version.sql [moved from src/core/SQL/SQLite/2/setup_080_version.sql with 100% similarity]
src/core/SQL/SQLite/3/update_username.sql [moved from src/core/SQL/SQLite/2/update_username.sql with 100% similarity]
src/core/SQL/SQLite/3/update_userpassword.sql [moved from src/core/SQL/SQLite/2/update_userpassword.sql with 100% similarity]
src/core/SQL/SQLite/3/upgrade_000_update_backlog_flags.sql [new file with mode: 0644]
src/core/SQL/SQLite/3/upgrade_010_update_schemaversion.sql [new file with mode: 0644]
src/core/coresession.cpp
src/core/ctcphandler.cpp
src/core/ctcphandler.h
src/core/ircserverhandler.cpp
src/core/sql.qrc
src/core/userinputhandler.cpp
version.inc

index 1676e33..2970fb6 100644 (file)
@@ -705,7 +705,8 @@ void NetworkModel::updateBufferActivity(const Message &msg) {
   if(msg.type() == Message::Plain || msg.type() == Message::Notice)
     level |= BufferItem::NewMessage;
 
-  if(msg.flags() & Message::Highlight)
+  const Network *net = Client::network(msg.bufferInfo().networkId());
+  if(net && msg.text().contains(net->myNick()))
     level |= BufferItem::Highlight;
   
   bufferItem(msg.bufferInfo())->updateActivity(level);
index 1411f3b..0c9c3d3 100644 (file)
@@ -32,8 +32,28 @@ class Message {
 
 public:
   /** The different types a message can have for display */
-  enum Type { Plain, Notice, Action, Nick, Mode, Join, Part, Quit, Kick, Kill, Server, Info, Error };
-  enum Flags { None = 0, Self = 1, PrivMsg = 2, Highlight = 4 };
+  enum Type {
+    Plain,
+    Notice,
+    Action,
+    Nick,
+    Mode,
+    Join,
+    Part,
+    Quit,
+    Kick,
+    Kill,
+    Server,
+    Info,
+    Error
+  };
+
+  enum Flags {
+    None = 0,
+    Self = 1
+  };
+  Q_DECLARE_FLAGS(MessageFlags, Flags)
+  
 
   Message(BufferInfo bufferInfo = BufferInfo(), Type type = Plain, QString text = "", QString sender = "", quint8 flags = None);
 
@@ -78,5 +98,6 @@ QDataStream &operator<<(QDataStream &out, const Message &msg);
 QDataStream &operator>>(QDataStream &in, Message &msg);
 
 Q_DECLARE_METATYPE(Message);
+Q_DECLARE_OPERATORS_FOR_FLAGS(Message::MessageFlags)
 
 #endif
diff --git a/src/core/SQL/SQLite/3/upgrade_000_update_backlog_flags.sql b/src/core/SQL/SQLite/3/upgrade_000_update_backlog_flags.sql
new file mode 100644 (file)
index 0000000..482505a
--- /dev/null
@@ -0,0 +1 @@
+UPDATE backlog SET flags = flags & 1
diff --git a/src/core/SQL/SQLite/3/upgrade_010_update_schemaversion.sql b/src/core/SQL/SQLite/3/upgrade_010_update_schemaversion.sql
new file mode 100644 (file)
index 0000000..4ef71dc
--- /dev/null
@@ -0,0 +1,3 @@
+UPDATE coreinfo
+SET value='3'
+WHERE key = 'schemaversion'
index e974c21..8e66738 100644 (file)
@@ -292,14 +292,8 @@ void CoreSession::msgFromClient(BufferInfo bufinfo, QString msg) {
 void CoreSession::recvMessageFromServer(Message::Type type, QString target, QString text, QString sender, quint8 flags) {
   NetworkConnection *netCon = qobject_cast<NetworkConnection*>(this->sender());
   Q_ASSERT(netCon);
-
-  QString bufferName;
-  if((flags & Message::PrivMsg) && !(flags & Message::Self))
-    bufferName = nickFromMask(sender);
-  else
-    bufferName = target;
-
-  BufferInfo bufferInfo = Core::bufferInfo(user(), netCon->networkId(), bufferName);
+  
+  BufferInfo bufferInfo = Core::bufferInfo(user(), netCon->networkId(), target);
   Message msg(bufferInfo, type, text, sender, flags);
   msg.setMsgId(Core::storeMessage(msg));
   Q_ASSERT(msg.msgId() != 0);
index 26697f8..153f6c0 100644 (file)
@@ -81,17 +81,21 @@ QString CtcpHandler::XdelimDequote(QString message) {
   return dequotedMessage;
 }
 
-QStringList CtcpHandler::parse(CtcpType ctcptype, QString prefix, QString target, QString message) {
-  QStringList messages;
+void CtcpHandler::parse(Message::Type messageType, QString prefix, QString target, QString message) {
   QString ctcp;
   
   //lowlevel message dequote
   QString dequotedMessage = dequote(message);
-  
+
+  CtcpType ctcptype = (messageType == Message::Notice)
+    ? CtcpReply
+    : CtcpQuery;
+
   // extract tagged / extended data
   while(dequotedMessage.contains(XDELIM)) {
-    if(dequotedMessage.indexOf(XDELIM) > 0) 
-      messages << dequotedMessage.section(XDELIM,0,0);
+    if(dequotedMessage.indexOf(XDELIM) > 0)
+      emit displayMsg(messageType, target, dequotedMessage.section(XDELIM,0,0), prefix);
+    // messages << dequotedMessage.section(XDELIM,0,0), prefix);
     ctcp = XdelimDequote(dequotedMessage.section(XDELIM,1,1));
     dequotedMessage = dequotedMessage.section(XDELIM,2,2);
     
@@ -101,10 +105,10 @@ QStringList CtcpHandler::parse(CtcpType ctcptype, QString prefix, QString target
 
     handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam));
   }
-  if(!dequotedMessage.isEmpty()) {
-    messages << dequotedMessage;
-  }
-  return messages;
+  
+  if(!dequotedMessage.isEmpty())
+    emit displayMsg(messageType, target, dequotedMessage, prefix);
+
 }
 
 QString CtcpHandler::pack(QString ctcpTag, QString message) {
index 3f1eecb..59db076 100644 (file)
@@ -34,7 +34,7 @@ public:
 
   enum CtcpType {CtcpQuery, CtcpReply};
 
-  QStringList parse(CtcpType, QString prefix, QString target, QString message);
+  void parse(Message::Type, QString prefix, QString target, QString message);
 
   QString dequote(QString);
   QString XdelimDequote(QString);
index cb4c153..6a220db 100644 (file)
@@ -272,10 +272,24 @@ void IrcServerHandler::handleNick(QString prefix, QList<QByteArray> params) {
 }
 
 void IrcServerHandler::handleNotice(QString prefix, QList<QByteArray> params) {
-  if(network()->currentServer().isEmpty() || network()->currentServer() == prefix)
+  if(params.count() < 2) {
+    qWarning() << "IrcServerHandler::handleNotice(): not enoug Parameters:" << prefix << serverDecode(params);
+    return;
+  }
+
+  // check if it's only a Server Message or if it's a regular Notice
+  if(network()->currentServer().isEmpty() || network()->currentServer() == prefix) {
     emit displayMsg(Message::Server, "", serverDecode(params[1]), prefix);
-  else
-    emit displayMsg(Message::Notice, "", userDecode(prefix, params[1]), prefix);
+    return;
+  }
+
+  QString target = serverDecode(params[0]);
+
+  // are we the target?
+  if(network()->isMyNick(target))
+    target = nickFromMask(target);
+
+  networkConnection->ctcpHandler()->parse(Message::Notice, prefix, target, userDecode(prefix, params[1]));
 }
 
 void IrcServerHandler::handlePart(QString prefix, QList<QByteArray> params) {
@@ -305,34 +319,19 @@ void IrcServerHandler::handlePrivmsg(QString prefix, QList<QByteArray> params) {
 
   QString target = serverDecode(params[0]);
 
-  // are we the target or is it a channel?
-  if(network()->isMyNick(target)) {
-    // it's possible to pack multiple privmsgs into one param using ctcp
-    QStringList messages = networkConnection->ctcpHandler()->parse(CtcpHandler::CtcpQuery, prefix, target, userDecode(ircuser->nick(), params[1]));
-    quint8 flags;
-    foreach(QString message, messages) {
-      flags = Message::PrivMsg;
-      if(message.contains(network()->myNick()))
-       flags |= Message::Highlight;
-      emit displayMsg(Message::Plain, "", message, prefix, flags);
-    }
-  } else {
-    // so it's probably a channel..
-    if(!isChannelName(target)) {
-      qWarning() << "received PRIVMSG with target" << target << "which is neither us nor a channel!";
-      return;
-    }
+  // are we the target?
+  if(network()->isMyNick(target))
+    target = nickFromMask(target);
 
-    QStringList messages = networkConnection->ctcpHandler()->parse(CtcpHandler::CtcpQuery, prefix, target, bufferDecode(target, params[1]));
-    quint8 flags;
-    foreach(QString message, messages) {
-      flags = Message::None;
-      if(message.contains(network()->myNick()))
-       flags |= Message::Highlight;
-      emit displayMsg(Message::Plain, target, message, prefix, flags);
-    }
-  }
+  // it's possible to pack multiple privmsgs into one param using ctcp
+  // - > we let the ctcpHandler do the work
+  networkConnection->ctcpHandler()->parse(Message::Plain, prefix, target, userDecode(ircuser->nick(), params[1]));
+//   QStringList messages = 
 
+//   foreach(QString message, messages) {
+//     emit displayMsg(Message::Plain, target, message, prefix);
+//   }
+  
 }
 
 void IrcServerHandler::handleQuit(QString prefix, QList<QByteArray> params) {
index 6498a91..73ed98d 100644 (file)
@@ -3,36 +3,38 @@
     <file>./SQL/SQLite/1/upgrade_000_drop_coreinfo.sql</file>
     <file>./SQL/SQLite/1/upgrade_010_create_coreinfo.sql</file>
     <file>./SQL/SQLite/1/upgrade_020_update_schemaversion.sql</file>
-    <file>./SQL/SQLite/2/delete_backlog_by_uid.sql</file>
-    <file>./SQL/SQLite/2/delete_buffers_by_uid.sql</file>
-    <file>./SQL/SQLite/2/delete_networks_by_uid.sql</file>
-    <file>./SQL/SQLite/2/delete_quasseluser.sql</file>
-    <file>./SQL/SQLite/2/insert_buffer.sql</file>
-    <file>./SQL/SQLite/2/insert_message.sql</file>
-    <file>./SQL/SQLite/2/insert_network.sql</file>
-    <file>./SQL/SQLite/2/insert_quasseluser.sql</file>
-    <file>./SQL/SQLite/2/insert_sender.sql</file>
-    <file>./SQL/SQLite/2/select_authuser.sql</file>
-    <file>./SQL/SQLite/2/select_bufferByName.sql</file>
-    <file>./SQL/SQLite/2/select_buffers.sql</file>
-    <file>./SQL/SQLite/2/select_lastMessage.sql</file>
-    <file>./SQL/SQLite/2/select_messageRange.sql</file>
-    <file>./SQL/SQLite/2/select_messages.sql</file>
-    <file>./SQL/SQLite/2/select_messagesOffset.sql</file>
-    <file>./SQL/SQLite/2/select_messagesSince.sql</file>
-    <file>./SQL/SQLite/2/select_messagesSinceOffset.sql</file>
-    <file>./SQL/SQLite/2/select_userid.sql</file>
-    <file>./SQL/SQLite/2/setup_000_quasseluser.sql</file>
-    <file>./SQL/SQLite/2/setup_010_sender.sql</file>
-    <file>./SQL/SQLite/2/setup_020_network.sql</file>
-    <file>./SQL/SQLite/2/setup_040_buffer.sql</file>
-    <file>./SQL/SQLite/2/setup_050_buffer_idx.sql</file>
-    <file>./SQL/SQLite/2/setup_060_backlog.sql</file>
-    <file>./SQL/SQLite/2/setup_070_coreinfo.sql</file>
-    <file>./SQL/SQLite/2/setup_080_version.sql</file>
-    <file>./SQL/SQLite/2/update_username.sql</file>
-    <file>./SQL/SQLite/2/update_userpassword.sql</file>
     <file>./SQL/SQLite/2/upgrade_000_drop_buffergroup.sql</file>
     <file>./SQL/SQLite/2/upgrade_010_update_schemaversion.sql</file>
+    <file>./SQL/SQLite/3/delete_backlog_by_uid.sql</file>
+    <file>./SQL/SQLite/3/delete_buffers_by_uid.sql</file>
+    <file>./SQL/SQLite/3/delete_networks_by_uid.sql</file>
+    <file>./SQL/SQLite/3/delete_quasseluser.sql</file>
+    <file>./SQL/SQLite/3/insert_buffer.sql</file>
+    <file>./SQL/SQLite/3/insert_message.sql</file>
+    <file>./SQL/SQLite/3/insert_network.sql</file>
+    <file>./SQL/SQLite/3/insert_quasseluser.sql</file>
+    <file>./SQL/SQLite/3/insert_sender.sql</file>
+    <file>./SQL/SQLite/3/select_authuser.sql</file>
+    <file>./SQL/SQLite/3/select_bufferByName.sql</file>
+    <file>./SQL/SQLite/3/select_buffers.sql</file>
+    <file>./SQL/SQLite/3/select_lastMessage.sql</file>
+    <file>./SQL/SQLite/3/select_messageRange.sql</file>
+    <file>./SQL/SQLite/3/select_messages.sql</file>
+    <file>./SQL/SQLite/3/select_messagesOffset.sql</file>
+    <file>./SQL/SQLite/3/select_messagesSince.sql</file>
+    <file>./SQL/SQLite/3/select_messagesSinceOffset.sql</file>
+    <file>./SQL/SQLite/3/select_userid.sql</file>
+    <file>./SQL/SQLite/3/setup_000_quasseluser.sql</file>
+    <file>./SQL/SQLite/3/setup_010_sender.sql</file>
+    <file>./SQL/SQLite/3/setup_020_network.sql</file>
+    <file>./SQL/SQLite/3/setup_040_buffer.sql</file>
+    <file>./SQL/SQLite/3/setup_050_buffer_idx.sql</file>
+    <file>./SQL/SQLite/3/setup_060_backlog.sql</file>
+    <file>./SQL/SQLite/3/setup_070_coreinfo.sql</file>
+    <file>./SQL/SQLite/3/setup_080_version.sql</file>
+    <file>./SQL/SQLite/3/update_username.sql</file>
+    <file>./SQL/SQLite/3/update_userpassword.sql</file>
+    <file>./SQL/SQLite/3/upgrade_000_update_backlog_flags.sql</file>
+    <file>./SQL/SQLite/3/upgrade_010_update_schemaversion.sql</file>
 </qresource>
 </RCC>
index ee65f5f..69d08c4 100644 (file)
@@ -146,12 +146,14 @@ void UserInputHandler::handleMode(QString bufname, QString msg) {
 // TODO: show privmsgs
 void UserInputHandler::handleMsg(QString bufname, QString msg) {
   Q_UNUSED(bufname)
-  QString nick = msg.section(" ", 0, 0);
-  msg = msg.section(" ", 1);
-  if(nick.isEmpty() || msg.isEmpty()) return;
+  if(!msg.contains(' '))
+    return;
+      
   QStringList params;
-  params << nick << msg;
-  emit putCmd("PRIVMSG", params);
+  params << msg.section(' ', 0, 0);
+  params << msg.section(' ', 1);
+
+  emit putCmd("PRIVMSG", msg.split(' '));
 }
 
 void UserInputHandler::handleNick(QString bufname, QString msg) {
@@ -176,13 +178,14 @@ void UserInputHandler::handlePart(QString bufname, QString msg) {
 
 // TODO: implement queries
 void UserInputHandler::handleQuery(QString bufname, QString msg) {
-  // QString nick = msg.section(' ', 0, 0);
-  
+  Q_UNUSED(bufname)
+  QString target = msg.section(' ', 0, 0);
+  QString message = msg.section(' ', 1);
+  if(message.isEmpty())
+    emit displayMsg(Message::Server, target, "Starting query with " + target, network()->myNick(), Message::Self);
+  else
+    emit displayMsg(Message::Plain, target, message, network()->myNick(), Message::Self);
   handleMsg(bufname, msg);
-  
-  // TODO: usenetworkids
-//   if(!nick.isEmpty())
-//     emit queryRequested(network, nick);
 }
 
 void UserInputHandler::handleQuit(QString bufname, QString msg) {
@@ -200,11 +203,7 @@ void UserInputHandler::handleSay(QString bufname, QString msg) {
   QStringList params;
   params << bufname << msg;
   emit putCmd("PRIVMSG", params);
-  if(isChannelName(bufname)) {
-    emit displayMsg(Message::Plain, params[0], msg, network()->myNick(), Message::Self);
-  } else {
-    emit displayMsg(Message::Plain, params[0], msg, network()->myNick(), Message::Self|Message::PrivMsg);
-  }
+  emit displayMsg(Message::Plain, params[0], msg, network()->myNick(), Message::Self);
 }
 
 void UserInputHandler::handleTopic(QString bufname, QString msg) {
index 9876fc6..4a3ac03 100644 (file)
@@ -5,7 +5,7 @@
 
   quasselVersion = "0.2.0-pre";
   quasselDate = "2008-02-03";
-  quasselBuild = 445;
+  quasselBuild = 447;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 437;