ukui-search/libsearch/appdata/application-property-helper...

168 lines
5.0 KiB
C++
Raw Normal View History

#include "application-property-helper.h"
#include <QDateTime>
using namespace UkuiSearch;
namespace UkuiSearch {
class ApplicationPropertyHelperPrivate
{
friend class ApplicationPropertyHelper;
private:
ApplicationProperty::Property m_property;
QString m_databaseField;
QMetaType::Type m_valueType;
};
}
ApplicationPropertyHelper::ApplicationPropertyHelper(): d(new ApplicationPropertyHelperPrivate)
{
d->m_property = ApplicationProperty::Invalid;
d->m_valueType = QMetaType::UnknownType;
}
ApplicationPropertyHelper::ApplicationPropertyHelper(ApplicationProperty::Property property): d(new ApplicationPropertyHelperPrivate)
{
d->m_property = property;
switch (property) {
case ApplicationProperty::DesktopFilePath:
d->m_databaseField = "DESKTOP_FILE_PATH";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::ModifiedTime:
d->m_databaseField = "MODIFYED_TIME";
d->m_valueType = QMetaType::QDateTime;
break;
case ApplicationProperty::InsertTime:
d->m_databaseField = "INSERT_TIME";
d->m_valueType = QMetaType::QDateTime;
break;
case ApplicationProperty::LocalName:
d->m_databaseField = "LOCAL_NAME";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::NameEn:
d->m_databaseField = "NAME_EN";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::NameZh:
d->m_databaseField = "NAME_EN";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::PinyinName:
d->m_databaseField = "PINYIN_NAME";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::FirstLetterOfPinyin:
d->m_databaseField = "FIRST_LETTER_OF_PINYIN";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::FirstLetterAll:
d->m_databaseField = "FIRST_LETTER_ALL";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::Icon:
d->m_databaseField = "ICON";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::Type:
d->m_databaseField = "TYPE";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::Category:
d->m_databaseField = "CATEGORY";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::Exec:
d->m_databaseField = "EXEC";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::Comment:
d->m_databaseField = "CATEGORY";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::Md5:
d->m_databaseField = "MD5";
d->m_valueType = QMetaType::QString;
break;
case ApplicationProperty::LaunchTimes:
d->m_databaseField = "LAUNCH_TIMES";
d->m_valueType = QMetaType::Int;
break;
case ApplicationProperty::Favorites:
d->m_databaseField = "FAVORITES";
d->m_valueType = QMetaType::Int;
break;
case ApplicationProperty::Launched:
d->m_databaseField = "LAUNCHED";
d->m_valueType = QMetaType::Int;
break;
case ApplicationProperty::Top:
d->m_databaseField = "TOP";
d->m_valueType = QMetaType::Int;
break;
case ApplicationProperty::Lock:
d->m_databaseField = "LOCK";
d->m_valueType = QMetaType::Int;
break;
case ApplicationProperty::DontDisplay:
d->m_databaseField = "DONT_DISPLAY";
d->m_valueType = QMetaType::Int;
break;
case ApplicationProperty::AutoStart:
d->m_databaseField = "AUTO_START";
d->m_valueType = QMetaType::Int;
}
}
ApplicationPropertyHelper::ApplicationPropertyHelper(const ApplicationPropertyHelper &other): d(new ApplicationPropertyHelperPrivate(*other.d))
{
}
ApplicationPropertyHelper::~ApplicationPropertyHelper()
{
if(d) {
delete d;
d = nullptr;
}
}
ApplicationPropertyHelper &ApplicationPropertyHelper::operator =(const ApplicationPropertyHelper &rhs)
{
*d = *rhs.d;
return *this;
}
bool ApplicationPropertyHelper::operator ==(const ApplicationPropertyHelper &rhs) const
{
return d->m_databaseField == rhs.d->m_databaseField && d->m_valueType == rhs.d->m_valueType;
}
ApplicationProperty::Property ApplicationPropertyHelper::info()
{
return d->m_property;
}
QString ApplicationPropertyHelper::dataBaseField()
{
return d->m_databaseField;
}
QMetaType::Type ApplicationPropertyHelper::valueType()
{
return d->m_valueType;
}
QString ApplicationPropertyHelper::toDataBaseString(QVariant &value)
{
switch (d->m_valueType) {
case QMetaType::Type::UnknownType:
return QString();
case QMetaType::Type::QString:
return value.toString();
case QMetaType::Type::QDateTime:
return value.toDateTime().toString("yyyy-MM-dd hh:mm:ss");
default:
return {};
break;
}
}