Konsole
TabTitleFormatAction.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "TabTitleFormatAction.h"
00022
00023
00024 #include <QList>
00025 #include <QMenu>
00026
00027
00028 #include <KLocale>
00029
00030 using namespace Konsole;
00031
00032 const TabTitleFormatAction::Element TabTitleFormatAction::_localElements[] =
00033 {
00034 { "%n" , I18N_NOOP("Program Name") },
00035 { "%d" , I18N_NOOP("Current Directory (Short)") },
00036 { "%D" , I18N_NOOP("Current Directory (Long)") },
00037 { "%w" , I18N_NOOP("Window Title Set by Shell") },
00038 { "%#" , I18N_NOOP("Session number") }
00039 };
00040 const int TabTitleFormatAction::_localElementCount = 5;
00041 const TabTitleFormatAction::Element TabTitleFormatAction::_remoteElements[] =
00042 {
00043 { "%u" , I18N_NOOP("User Name") },
00044 { "%h" , I18N_NOOP("Remote Host (Short)") },
00045 { "%H" , I18N_NOOP("Remote Host (Long)") },
00046 { "%w" , I18N_NOOP("Window Title Set by Shell") },
00047 { "%#" , I18N_NOOP("Session number") }
00048 };
00049 const int TabTitleFormatAction::_remoteElementCount = 5;
00050
00051 TabTitleFormatAction::TabTitleFormatAction(QObject* parent)
00052 : QAction(parent)
00053 , _context(Session::LocalTabTitle)
00054 {
00055 setMenu( new QMenu() );
00056 connect( menu() , SIGNAL(triggered(QAction*)) , this , SLOT(fireElementSelected(QAction*)) );
00057 }
00058 TabTitleFormatAction::~TabTitleFormatAction()
00059 {
00060 menu()->deleteLater();
00061 }
00062 void TabTitleFormatAction::fireElementSelected(QAction* action)
00063 {
00064 emit dynamicElementSelected(action->data().value<QString>());
00065 }
00066 void TabTitleFormatAction::setContext(Session::TabTitleContext context)
00067 {
00068 _context = context;
00069
00070 menu()->clear();
00071
00072 QList<QAction*> list;
00073
00074 int count = 0;
00075 const Element* array = 0;
00076
00077 if ( context == Session::LocalTabTitle )
00078 {
00079 count = _localElementCount;
00080 array = _localElements;
00081 }
00082 else if ( context == Session::RemoteTabTitle )
00083 {
00084 count = _remoteElementCount;
00085 array = _remoteElements;
00086 }
00087
00088 for ( int i = 0 ; i < count ; i++ )
00089 {
00090 QAction* action = new QAction(i18n(array[i].description),this);
00091 action->setData(array[i].element);
00092 list << action;
00093 }
00094
00095 menu()->addActions(list);
00096 }
00097 Session::TabTitleContext TabTitleFormatAction::context() const
00098 {
00099 return _context;
00100 }
00101
00102 #include "TabTitleFormatAction.moc"
00103