Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Note: to build and run this commit, some hacks are needed.
- Loading branch information
Showing
46 changed files
with
4,650 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<RCC> | ||
<qresource prefix="/img"> | ||
<file>resource/next.png</file> | ||
<file>resource/pause.png</file> | ||
<file>resource/play.png</file> | ||
<file>resource/previous.png</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#include "AppEnv.h" | ||
#include <QtCore> | ||
|
||
namespace Path { | ||
const QString Config = "/.config/mous"; | ||
const QString Plugin = "/lib/mous"; | ||
const QString Resource = "/share/mous"; | ||
} | ||
|
||
namespace Key { | ||
const QString IfNotUtf8 = "IfNotUtf8"; | ||
const QString TagEditorSplitterState = "TagEditorSplitterState"; | ||
const QString WindowGeometry = "WindowGeometry"; | ||
const QString WindowState = "WindowState"; | ||
const QString TabCount = "TabCount"; | ||
const QString TabIndex = "TabIndex"; | ||
const QString Volume = "Volume"; | ||
} | ||
|
||
bool AppEnv::Init() | ||
{ | ||
#ifdef CMAKE_INSTALL_PREFIX | ||
pluginDir = QString(CMAKE_INSTALL_PREFIX) + Path::Plugin; | ||
resourceDir = QString(CMAKE_INSTALL_PREFIX) + Path::Resource; | ||
#else | ||
QStringList libPathes = | ||
(QStringList() << ("/usr/local" + Path::Plugin) << ("/usr" + Path::Plugin)); | ||
foreach (QString path, libPathes) { | ||
if (QFileInfo(path).isDir()) { | ||
pluginDir = path; | ||
break; | ||
} | ||
} | ||
QStringList resPathes = | ||
(QStringList() << ("/usr/local" + Path::Resource) << ("/usr" + Path::Resource)); | ||
foreach (QString path, resPathes) { | ||
if (QFileInfo(path).isDir()) { | ||
resourceDir = path; | ||
break; | ||
} | ||
} | ||
#endif | ||
if (!pluginDir.isEmpty() && !resourceDir.isEmpty()) { | ||
InitFilePath(); | ||
return LoadConfig(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
void AppEnv::Save() | ||
{ | ||
QSettings settings(configFile, QSettings::IniFormat); | ||
settings.setValue(Key::IfNotUtf8, ifNotUtf8); | ||
settings.setValue(Key::WindowGeometry, windowGeometry); | ||
settings.setValue(Key::WindowState, windowState); | ||
settings.setValue(Key::TagEditorSplitterState, tagEditorSplitterState); | ||
settings.setValue(Key::TabCount, tabCount); | ||
settings.setValue(Key::TabIndex, tabIndex); | ||
settings.setValue(Key::Volume, volume); | ||
settings.sync(); | ||
} | ||
|
||
void AppEnv::InitFilePath() | ||
{ | ||
configDir = QDir::homePath() + Path::Config + "/qt"; | ||
|
||
configFile = configDir + "/config"; | ||
qDebug() << "configFile" << configFile; | ||
|
||
QString locale = QLocale::system().name(); | ||
translationFile = resourceDir + "/qt/mous-qt_" + locale; | ||
qDebug() << "locale:" << locale; | ||
qDebug() << "translationFile:" << translationFile; | ||
} | ||
|
||
bool AppEnv::LoadConfig() | ||
{ | ||
if (!CheckDefaultConfig()) | ||
return false; | ||
|
||
QSettings settings(configFile, QSettings::IniFormat); | ||
ifNotUtf8 = settings.value(Key::IfNotUtf8).toString(); | ||
windowGeometry = settings.value(Key::WindowGeometry).toByteArray(); | ||
windowState = settings.value(Key::WindowState).toByteArray(); | ||
tagEditorSplitterState = settings.value(Key::TagEditorSplitterState).toByteArray(); | ||
tabCount = settings.value(Key::TabCount).toInt(); | ||
tabIndex = settings.value(Key::TabIndex).toInt(); | ||
volume = settings.value(Key::Volume).toInt(); | ||
return true; | ||
} | ||
|
||
bool AppEnv::CheckDefaultConfig() | ||
{ | ||
QString configRoot = QDir::homePath() + Path::Config + "/qt"; | ||
QFileInfo configRootInfo(configRoot); | ||
if (configRootInfo.exists()) { | ||
if (!configRootInfo.isDir() || !configRootInfo.isWritable()) | ||
return false; | ||
} else { | ||
QDir().mkpath(configRoot); | ||
} | ||
|
||
QFileInfo configFileInfo(configFile); | ||
if (configFileInfo.exists()) { | ||
if (!configFileInfo.isFile() || !configFileInfo.isWritable()) | ||
return false; | ||
else | ||
return true; | ||
} else { | ||
QFile(configFile).open(QIODevice::WriteOnly); | ||
} | ||
|
||
QSettings settings(configFile, QSettings::IniFormat); | ||
settings.setValue(Key::IfNotUtf8, "GBK"); | ||
settings.setValue(Key::WindowGeometry, QByteArray()); | ||
settings.setValue(Key::WindowState, QByteArray()); | ||
settings.setValue(Key::TagEditorSplitterState, QByteArray()); | ||
settings.setValue(Key::TabCount, 1); | ||
settings.setValue(Key::TabIndex, 0); | ||
settings.setValue(Key::Volume, -1); | ||
settings.sync(); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef APPENV_H | ||
#define APPENV_H | ||
|
||
#include <QString> | ||
#include <scx/Singleton.hpp> | ||
|
||
struct AppEnv | ||
{ | ||
public: | ||
bool Init(); | ||
void Save(); | ||
|
||
public: | ||
// path | ||
QString configDir; | ||
QString pluginDir; | ||
QString resourceDir; | ||
|
||
QString configFile; | ||
QString translationFile; | ||
|
||
// config | ||
QString ifNotUtf8; | ||
|
||
// ui && status | ||
QByteArray windowGeometry; | ||
QByteArray windowState; | ||
QByteArray tagEditorSplitterState; | ||
int tabCount; | ||
int tabIndex; | ||
int volume; | ||
|
||
private: | ||
void InitFilePath(); | ||
bool LoadConfig(); | ||
bool CheckDefaultConfig(); | ||
}; | ||
|
||
typedef scx::Singleton<AppEnv> GlobalAppEnv; | ||
|
||
#endif // APPENV_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "CustomHeadTabWidget.hpp" | ||
using namespace sqt; | ||
|
||
CustomHeadTabWidget::CustomHeadTabWidget(QWidget *parent): | ||
QTabWidget(parent) | ||
{ | ||
setMouseTracking(true); | ||
} | ||
|
||
void CustomHeadTabWidget::SetTabBar(QTabBar *tb) | ||
{ | ||
QTabWidget::setTabBar(tb); | ||
} | ||
|
||
void CustomHeadTabWidget::mouseDoubleClickEvent(QMouseEvent* event) | ||
{ | ||
QTabWidget::mouseDoubleClickEvent(event); | ||
|
||
if (!tabBar()->underMouse()) | ||
emit SigDoubleClick(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <QtWidgets> | ||
|
||
namespace sqt { | ||
|
||
class CustomHeadTabWidget: public QTabWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
CustomHeadTabWidget(QWidget * parent = 0); | ||
void SetTabBar(QTabBar* tb); | ||
|
||
signals: | ||
void SigDoubleClick(); | ||
|
||
private: | ||
void mouseDoubleClickEvent(QMouseEvent* event); | ||
}; | ||
|
||
} |
Oops, something went wrong.