Moving alias expansion yet again - this time into AliasManager itself
[quassel.git] / src / qtui / settingspages / aliasesmodel.cpp
index 8df2279..d85feed 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   Copyright (C) 2005-09 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -52,7 +52,14 @@ QVariant AliasesModel::data(const QModelIndex &index, int role) const {
        "<b>Example:</b> \"foo\" can be used per /foo";
     case 1:
       return "<b>The string the shortcut will be expanded to</b><br />"
-       "$i represenents the i'th parameter. $0 the whole string.<br />"
+       "<b>special variables:</b><br />"
+       " - <b>$i</b> represents the i'th parameter.<br />"
+       " - <b>$i..j</b> represents the i'th to j'th parameter separated by spaces.<br />"
+       " - <b>$i..</b> represents all parameters from i on separated by spaces.<br />"
+       " - <b>$i:hostname</b> represents the hostname of the user identified by the i'th parameter or a * if unknown.<br />"
+       " - <b>$0</b> the whole string.<br />"
+       " - <b>$nick</b> your current nickname<br />"
+       " - <b>$channel</b> the name of the selected channel<br /><br />"
        "Multiple commands can be separated with semicolons<br /><br />"
        "<b>Example:</b> \"Test $1; Test $2; Test All $0\" will be expanded to three separate messages \"Test 1\", \"Test 2\" and \"Test All 1 2 3\" when called like /test 1 2 3";
     default:
@@ -80,7 +87,7 @@ bool AliasesModel::setData(const QModelIndex &index, const QVariant &value, int
   QString newValue = value.toString();
   if(newValue.isEmpty())
     return false;
-  
+
   switch(index.column()) {
   case 0:
     if(aliasManager().contains(newValue)) {
@@ -110,6 +117,24 @@ void AliasesModel::newAlias() {
   endInsertRows();
 }
 
+void AliasesModel::loadDefaults() {
+  AliasManager &manager = cloneAliasManager();
+
+  if(!manager.isEmpty()) {
+    beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
+    for(int i = rowCount() - 1; i >= 0; i--)
+      manager.removeAt(i);
+    endRemoveRows();
+  }
+
+  AliasManager::AliasList defaults = AliasManager::defaults();
+  beginInsertRows(QModelIndex(), 0, defaults.count() - 1);
+  foreach(AliasManager::Alias alias, defaults) {
+    manager.addAlias(alias.name, alias.expansion);
+  }
+  endInsertRows();
+}
+
 void AliasesModel::removeAlias(int index) {
   if(index < 0 || index >= rowCount())
     return;
@@ -195,7 +220,7 @@ void AliasesModel::initDone() {
 }
 
 void AliasesModel::clientConnected() {
-  _aliasManager = AliasManager();
+  _aliasManager = ClientAliasManager();
   Client::signalProxy()->synchronize(&_aliasManager);
   connect(&_aliasManager, SIGNAL(initDone()), this, SLOT(initDone()));
   connect(&_aliasManager, SIGNAL(updated(const QVariantMap &)), this, SLOT(revert()));
@@ -203,8 +228,8 @@ void AliasesModel::clientConnected() {
 
 void AliasesModel::clientDisconnected() {
   // clear alias managers
-  _aliasManager = AliasManager();
-  _clonedAliasManager = AliasManager();
+  _aliasManager = ClientAliasManager();
+  _clonedAliasManager = ClientAliasManager();
   reset();
   emit modelReady(false);
 }