Revision
14285
Author
jmesquita
Date
2009-07-17 17:17:58 -0500 (Fri, 17 Jul 2009)

Log Message

NEW FEATURE: Command history activated upon ARROW_DOWN key.

Modified Paths

Diff

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/completers.cpp (14284 => 14285)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/completers.cpp	2009-07-17 20:54:08 UTC (rev 14284)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/completers.cpp	2009-07-17 22:17:58 UTC (rev 14285)
@@ -13,10 +13,9 @@
 {
     QStringList list = listModel->stringList();
     if (!list.contains(cmd, Qt::CaseInsensitive))
-        list << cmd;
+        list.prepend(cmd);
 
     listModel->setStringList(list);
-    qDebug() << list;
 }
 QAbstractItemModel *cmdHistory::modelFromFile(const QString& fileName)
  {

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/consolepage.cpp (14284 => 14285)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/consolepage.cpp	2009-07-17 20:54:08 UTC (rev 14284)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/consolepage.cpp	2009-07-17 22:17:58 UTC (rev 14285)
@@ -46,13 +46,14 @@
 consolePage::consolePage(QWidget *parent) :
     QWidget(parent),
     m_ui(new Ui::consolePage),
-    histCompleter(new cmdHistory)
+    histCompleter(new cmdHistory),
+    lineCmdEventFilter(new keyPressEventFilter(histCompleter))
 {
     m_ui->setupUi(this);
     setConsoleBackground();
     connect(m_ui->comboLogLevel, SIGNAL(currentIndexChanged(int)),
             this, SLOT(loglevelChanged(int)));
-    m_ui->lineCmd->setCompleter(histCompleter);
+    m_ui->lineCmd->installEventFilter(lineCmdEventFilter);
 }
 consolePage::~consolePage()
 {
@@ -224,3 +225,26 @@
     QSettings settings(SETTINGS_ORGANIZATION, SETTINGS_APPLICATION);
     settings.setValue(QString("servers/%1/loglevel").arg(host), m_ui->comboLogLevel->currentIndex());
 }
+/************************************************************************/
+/* keyPressEventFilter                                                  */
+/************************************************************************/
+keyPressEventFilter::keyPressEventFilter(cmdHistory* histCompleter) :
+        histCompleter(histCompleter){}
+keyPressEventFilter::~keyPressEventFilter(){}
+bool keyPressEventFilter::eventFilter(QObject *obj, QEvent *e)
+{
+    if (e->type() == QEvent::KeyPress)
+    {
+        // TODO: Might be good to check settings
+        QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
+        if (keyEvent->key() == Qt::Key_Up)
+        {
+            QLineEdit * lineCmd = static_cast<QLineEdit *>(obj);
+            lineCmd->setCompleter(histCompleter);
+            histCompleter->setCompletionPrefix(lineCmd->text());
+            histCompleter->complete();
+            return true;
+        }
+    }
+    return QObject::eventFilter(obj, e);
+}

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/include/consolepage.h (14284 => 14285)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/include/consolepage.h	2009-07-17 20:54:08 UTC (rev 14284)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/include/consolepage.h	2009-07-17 22:17:58 UTC (rev 14285)
@@ -12,6 +12,7 @@
 class ESLeventLog;
 class ESLconnection;
 class cmdHistory;
+class keyPressEventFilter;
 
 class consolePage : public QWidget {
     Q_OBJECT
@@ -42,9 +43,20 @@
     QAbstractItemModel *modelFromFile(const QString& fileName);
     Ui::consolePage *m_ui;
     ESLconnection *eslConnection;
+    cmdHistory *histCompleter;
+    keyPressEventFilter *lineCmdEventFilter;
     QString host;
+};
+
+class keyPressEventFilter : public QObject {
+    Q_OBJECT
+public:
+    keyPressEventFilter(cmdHistory * histCompleter);
+    virtual ~keyPressEventFilter();
+protected:
+    bool eventFilter(QObject *obj, QEvent *e);
+private:
     cmdHistory *histCompleter;
-
 };
 
 #endif // CONSOLEPAGE_H