Kxkb: move LayoutUnit struct into its own file and add getLayoutName function

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/438/head
Mavridis Philippe 11 months ago
parent f2dbf5b903
commit 9647d4c7ff
No known key found for this signature in database
GPG Key ID: 93F66F98F906147D

@ -248,7 +248,6 @@ void KXKBApp::prevLayout()
setLayout(layout);
}
void KXKBApp::menuActivated(int id)
{
if( KxkbLabelController::START_MENU_ID <= id

@ -19,6 +19,8 @@
#include <tqptrqueue.h>
#include <tqmap.h>
#include "layoutunit.h"
struct XkbOptions {
TQString layouts;
TQString variants;
@ -36,59 +38,6 @@ enum SwitchingPolicy {
SWITCH_POLICY_COUNT = 3
};
inline TQString createPair(TQString key, TQString value)
{
if( value.isEmpty() )
return key;
return TQString("%1(%2)").arg(key, value);
}
struct LayoutUnit {
TQString layout;
TQString variant;
TQString displayName;
LayoutUnit() {}
LayoutUnit(TQString layout_, TQString variant_):
layout(layout_),
variant(variant_)
{}
LayoutUnit(TQString pair) {
setFromPair( pair );
}
void setFromPair(const TQString& pair) {
layout = parseLayout(pair);
variant = parseVariant(pair);
}
TQString toPair() const {
return createPair(layout, variant);
}
bool operator<(const LayoutUnit& lu) const {
return layout<lu.layout ||
(layout==lu.layout && variant<lu.variant);
}
bool operator!=(const LayoutUnit& lu) const {
return layout!=lu.layout || variant!=lu.variant;
}
bool operator==(const LayoutUnit& lu) const {
// kdDebug() << layout << "==" << lu.layout << "&&" << variant << "==" << lu.variant << endl;
return layout==lu.layout && variant==lu.variant;
}
//private:
static const TQString parseLayout(const TQString &layvar);
static const TQString parseVariant(const TQString &layvar);
};
extern const LayoutUnit DEFAULT_LAYOUT_UNIT;
extern const char* DEFAULT_MODEL;

@ -90,13 +90,15 @@ void KxkbLabelController::initLayoutList(const TQValueList<LayoutUnit>& layouts,
const TQString layoutName = (*it).layout;
const TQString variantName = (*it).variant;
const TQPixmap& layoutPixmap = LayoutIcon::getInstance().findPixmap(layoutName, PIXMAP_STYLE_CONTEXTMENU, (*it).displayName);
const TQPixmap pix = iconeffect.apply(layoutPixmap, TDEIcon::Small, TDEIcon::DefaultState);
const TQPixmap& layoutPixmap = LayoutIcon::getInstance().findPixmap(
(*it).layout, PIXMAP_STYLE_CONTEXTMENU, (*it).displayName);
const TQPixmap pix = iconeffect.apply(layoutPixmap, TDEIcon::Small,
TDEIcon::DefaultState);
TQString fullName = rules.getLayoutName((*it));
contextMenu->insertItem(pix, fullName, START_MENU_ID + cnt,
m_menuStartIndex + cnt);
TQString fullName = i18n((rules.layouts()[layoutName]));
if( variantName.isEmpty() == false )
fullName += " (" + variantName + ")";
contextMenu->insertItem(pix, fullName, START_MENU_ID + cnt, m_menuStartIndex + cnt);
m_descriptionMap.insert((*it).toPair(), fullName);
cnt++;

@ -0,0 +1,64 @@
//
//
// Author: Andriy Rysin <rysin@kde.org>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef _LAYOUTUNIT_H
#define _LAYOUTUNIT_H
#include <tqstring.h>
inline TQString createPair(TQString key, TQString value)
{
if (value.isEmpty()) return key;
return TQString("%1(%2)").arg(key, value);
}
struct LayoutUnit {
TQString layout;
TQString variant;
TQString displayName;
LayoutUnit() {}
LayoutUnit(TQString layout_, TQString variant_):
layout(layout_),
variant(variant_)
{}
LayoutUnit(TQString pair) {
setFromPair( pair );
}
void setFromPair(const TQString& pair) {
layout = parseLayout(pair);
variant = parseVariant(pair);
}
TQString toPair() const {
return createPair(layout, variant);
}
bool operator<(const LayoutUnit& lu) const {
return layout<lu.layout ||
(layout==lu.layout && variant<lu.variant);
}
bool operator!=(const LayoutUnit& lu) const {
return layout!=lu.layout || variant!=lu.variant;
}
bool operator==(const LayoutUnit& lu) const {
// kdDebug() << layout << "==" << lu.layout << "&&" << variant << "==" << lu.variant << endl;
return layout==lu.layout && variant==lu.variant;
}
//private:
static const TQString parseLayout(const TQString &layvar);
static const TQString parseVariant(const TQString &layvar);
};
#endif // _LAYOUTUNIT_H

@ -73,3 +73,10 @@ XkbRules::getAvailableVariants(const TQString& layout)
return *result;
}
TQString XkbRules::getLayoutName(LayoutUnit layout) const {
TQString fullName = i18n(m_layouts[layout.layout]);
if (!layout.variant.isEmpty()) {
fullName += " (" + layout.variant + ")";
}
return fullName;
}

@ -5,6 +5,7 @@
#include <tqdict.h>
#include <tqmap.h>
#include "layoutunit.h"
class XkbRules
{
@ -18,6 +19,8 @@ public:
TQStringList getAvailableVariants(const TQString& layout);
TQString getLayoutName(LayoutUnit layout) const;
protected:
void loadRules(TQString filename, bool layoutsOnly=false);

Loading…
Cancel
Save