Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wuqiong committed Jan 4, 2015
1 parent 2f65e3a commit 7200f52
Show file tree
Hide file tree
Showing 23 changed files with 1,565 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@
*.exe
*.out
*.app

#qt
*.pro.user
*.pro.user*

#mac os x
.DS_Store
Binary file added KylinPlayer.icns
Binary file not shown.
Binary file added KylinPlayer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions KylinPlayer.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#-------------------------------------------------
#
# Project created by QtCreator 2014-07-19T11:54:34
#
#-------------------------------------------------

QT += core gui multimedia network sql multimediawidgets
linux {
QT += x11extras
LIBS += -lXext -lX11
}
mac {
ICON = KylinPlayer.icns
}
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = KylinPlayer
TEMPLATE = app


SOURCES += main.cpp\
playermainwindow.cpp \
network.cpp \
database.cpp \
osdlyricswidget.cpp

HEADERS += playermainwindow.h \
network.h \
common.h \
database.h \
osdlyricswidget.h

FORMS += playermainwindow.ui

RESOURCES += \
resource.qrc
Binary file added Qt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
KylinPlayer
===========

A Cross Platform OpenSource Mini Music Player with OSD of BaiduFM on Ubuntu Kylin Linux, Mac OS X and Windows.
A Cross Platform OpenSource Mini Music Player with OSD of BaiduFM on Ubuntu Kylin Linux, Mac OS X and Windows.

这些个示例项目是2014年7月底在长沙某高校的一个为期三天的一个UbuntuKylin平台的Qt5开发技术的一个培训项目;
主要为了在高校师生群体中推广UbuntuKylin以及开源操作系统和开源软件, 课程借以介绍Qt5的一些简单使用来推广Qt开发.
当时上课没有及时的录制视频,后来单独复述录制了此课程的视频教程,现已把视频公开在51cto学院;
为了代码和视频配套,供网友下载参考,所以把代码也开源在此(Github).

欢迎大家去学习和改进. 如果有兴趣去进一步完善美化此项目, 可以联系我.

基本要求:
OS: Ubuntu/Mac OS X/Windows
SDK:Qt5.x
IDE:Qt Creator

44 changes: 44 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef COMMON_H
#define COMMON_H
#include <QObject>
#include <QString>
#include <stdint.h>


typedef struct KChannel
{
QString id;
QString title;
}KChannel;

typedef struct KMediaInfo
{
int32_t id;
QString songId;
QString songName;
QString artistName;
QString albumName;
QString songPicUrl;
QString lrcUrl;
QString mp3Url;
bool operator ==(const KMediaInfo &info)
{
return this->id == info.id;
}
KMediaInfo& operator =(const KMediaInfo &info)
{
this->id = info.id;
this->albumName = info.albumName;
this->artistName = info.artistName;
this->lrcUrl = info.lrcUrl;
this->mp3Url = info.mp3Url;
this->songId = info.songId;
this->songName = info.songName;
this->songPicUrl = info.songPicUrl;
return *this;
}
}KMediaInfo;

#endif // COMMON_H


102 changes: 102 additions & 0 deletions database.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include "database.h"
#include <QDebug>


#define DATABASE_CREATE_SQL "CREATE DATABASE \
`KylinPlayer` DEFAULT CHARACTER SET utf8;"

#define TABLE_CREATE_SQL \
"CREATE TABLE FavoriteSong "\
"(id INTEGER PRIMARY KEY, song_id NUMERIC, song_name TEXT, album_name TEXT, "\
"singer_name TEXT, song_url TEXT, artcover_url TEXT, lrc_url TEXT,UNIQUE(song_id));"

#define INSERT_SONG_SQL "REPLACE INTO FavoriteSong \
(song_id, song_name, album_name, singer_name, \
song_url, artcover_url, lrc_url) \
VALUES (?, ?, ?, ?, ?, ?, ?)"

#define SELECT_SONG_SQL "SELECT song_id, song_name, album_name, \
singer_name,song_url,artcover_url,lrc_url \
FROM FavoriteSong;"


Database::Database(QObject *parent) :
QObject(parent)
{
}

bool Database::initDataBase()
{
qDebug() << QSqlDatabase::drivers();
this->database = QSqlDatabase::addDatabase("QSQLITE");
if(!this->database.isValid())
{
return false;
}
qDebug() << "isValid";
QString dbPath = QDir::homePath() + "/.KylinPlayer.db3";
dbPath = QDir::toNativeSeparators(dbPath);
this->database.setDatabaseName(dbPath);//database name
// this->database.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");//use SSL
if(this->database.open())
{
qDebug()<<"open "<<this->database.lastError().driverText();
}else
{
qDebug()<<"open failed";
return false;
}
qDebug()<< this->database.databaseName();
qDebug()<< this->database.tables();
QSqlQuery query(this->database);
#if 0
query.exec(DATABASE_CREATE_SQL);
query.exec("use KylinPlayer;");
#endif
bool ret = query.exec(TABLE_CREATE_SQL);

return ret;
}

bool Database::addFavoriteSong(KMediaInfo songInfo)
{
QSqlQuery query(this->database);
query.prepare(INSERT_SONG_SQL);
query.addBindValue(songInfo.id);
query.addBindValue(songInfo.songName);
query.addBindValue(songInfo.albumName);
query.addBindValue(songInfo.artistName);
query.addBindValue(songInfo.mp3Url);
query.addBindValue(songInfo.songPicUrl);
query.addBindValue(songInfo.lrcUrl);
bool ret = query.exec();
qDebug() << "qurey exec:" << ret ;
query.finish();
return ret;
}

QList<KMediaInfo> *Database::getFavoriteSong()
{
QSqlQuery query(this->database);
QList<KMediaInfo> *mediaInfoList = new QList<KMediaInfo>();
bool ret = query.exec(SELECT_SONG_SQL);
if(!ret)
{
return NULL;
}
while(query.next())
{
KMediaInfo info;
info.id = query.value(0).toInt();
info.songId = QString("%1").arg(info.id);
info.songName = query.value(1).toString();
info.albumName = query.value(2).toString();
info.artistName = query.value(3).toString();
info.mp3Url = query.value(4).toString();
info.songPicUrl = query.value(5).toString();
info.lrcUrl = query.value(6).toString();
mediaInfoList->append(info);
}
query.finish();
return mediaInfoList;
}
24 changes: 24 additions & 0 deletions database.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef DATABASE_H
#define DATABASE_H

#include <QObject>
#include <QtSql>
#include <QList>
#include "common.h"
class Database : public QObject
{
Q_OBJECT
public:
explicit Database(QObject *parent = 0);

signals:

public slots:
bool initDataBase();
bool addFavoriteSong(KMediaInfo songInfo);
QList<KMediaInfo> *getFavoriteSong();
private:
QSqlDatabase database;
};

#endif // DATABASE_H
10 changes: 10 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "playermainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
PlayerMainWindow w;
w.show();
return a.exec();
}
Loading

0 comments on commit 7200f52

Please sign in to comment.