Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Version 1.4 beta , Added Quran Streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashid P committed Apr 1, 2021
1 parent 8d5db58 commit 99d9e16
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 21 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cmake_minimum_required(VERSION 3.9)
project(Quran-app VERSION 1.0 LANGUAGES CXX)
project(Quran-app VERSION 2.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.12.10\\msvc2017_64;C:\\Users\\Home\\vcpkg\\installed\\x64-windows")
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.15.2\\msvc2019_64;C:\\vcpkg\\installed\\x64-windows")
set(APP_ICON "src/icon.rc")

set(SRCS
Expand All @@ -25,10 +25,10 @@ if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Widgets Multimedia REQUIRED)
find_package(CURL CONFIG REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)

add_executable(qapp WIN32 ${SRCS} ${APP_ICON})

target_link_libraries(qapp PRIVATE Qt5::Widgets CURL::libcurl unofficial::sqlite3::sqlite3)
target_link_libraries(qapp PRIVATE Qt5::Widgets Qt5::Multimedia CURL::libcurl unofficial::sqlite3::sqlite3)
12 changes: 1 addition & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@
* Project Name : Quran app
* Description : an easy to use Quran Reading program in Qt5, supports translations in indian languages as well as quran audio streaming
* Specs :- Multi-language , stream quran
* Build-Dependencies : libcurl , qt5 libs, nlohmann json : https://github.com/nlohmann/json/ , libao-dev , libmpg123-dev
* Build-Dependencies : libcurl , qt5 libs, nlohmann json : https://github.com/nlohmann/json/
* Developer : Nashid P , Member of Muslim Programmers Community
*
***/

#include <QApplication>
#include <QSplashScreen>
#include <QTimer>
#include <iostream>
#include <string>
#include <curl/curl.h>
#include <cstdio>
#include "window.hpp"

void help_menu();
int check_option(int argc, char *argv[], int x);
bool isSurah(char *arg);
bool isInt(char *arg);
void process_option(int argc, char *argv[], int x);

int main(int argc, char *argv[])
{
// Initiate Qt Application
Expand Down
99 changes: 93 additions & 6 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@ Window::Window()
createMenu(); // Call createMenu() to configure MenuBar
setMenuBar(menuBar); // set MenuBar
MainLayout->addWidget(createComboBox()); // set ComboBox
MainLayout->addWidget(createPlayerUi()); // set PlayerUi
MainLayout->addWidget(createTextBox()); // set TextBox
MainWidget->setLayout(MainLayout); // set Layout
setCentralWidget(MainWidget); // set Main Widget
setWindowTitle("Quran app"); // set Window Title
setWindowTitle("Quran App"); // set Window Title
setMinimumWidth(800); // set Minimum Width of Window
setMinimumHeight(600); // set Minimum Height of Window
connect(surah, SIGNAL(currentTextChanged(QString)), this, SLOT(showSurah())); // Watch Changes in ComboBox surah
connect(translation, SIGNAL(currentTextChanged(QString)), this, SLOT(showTranslation())); // Watch Changes in ComboBox translation
connect(play, SIGNAL(clicked()), this, SLOT(set_play()));
connect(pause, SIGNAL(clicked()), this, SLOT(set_pause()));
connect(stop, SIGNAL(clicked()), this, SLOT(set_stop()));
}

void Window::createMenu()
Expand All @@ -67,9 +71,9 @@ void Window::createMenu()
menuBar = new QMenuBar;
Menu = new QMenu(tr("Menu"), this);
darkmode = Menu->addAction(tr("Dark Mode")); // Add Dark Mode Menu Entry
darkmode->setCheckable(true);
prayertimes = Menu->addAction(tr("Prayer Times"));
about = Menu->addAction(tr("About")); // Add About Menu Entry
darkmode->setCheckable(true);
menuBar->addMenu(Menu);
connect(about, SIGNAL(triggered()), this, SLOT(showAbout()));
connect(darkmode, SIGNAL(triggered()), this, SLOT(setDarkMode()));
Expand Down Expand Up @@ -123,6 +127,52 @@ QGroupBox *Window::createTextBox()
return group;
}

QGroupBox *Window::createPlayerUi()
{
// create Media Player UI

QGroupBox *PlayerBox = new QGroupBox(tr("Play Surah"));
QHBoxLayout *PlayerLayout = new QHBoxLayout;
play = new QPushButton("Play");
pause = new QPushButton("Pause");
stop = new QPushButton("Stop");
player = new QMediaPlayer;
player->setMedia(QuranUrl);
PlayerLayout->addWidget(play);
PlayerLayout->addWidget(pause);
PlayerLayout->addWidget(stop);
PlayerBox->setLayout(PlayerLayout);
return PlayerBox;

}


QUrl Window::getQuranUrl(int surah_number)
{
QUrl qurl;
std::string QuranUrl = "https://server8.mp3quran.net/afs/";
if(surah_number >= 1 && surah_number <= 9)
{
QuranUrl.append("00");
QuranUrl.append(std::to_string(surah_number));
QuranUrl.append(".mp3");
}
else if(surah_number >= 10 && surah_number <= 99)
{
QuranUrl.append("0");
QuranUrl.append(std::to_string(surah_number));
QuranUrl.append(".mp3");
}
else if(surah_number >= 100 && surah_number <= 114)
{
QuranUrl.append(std::to_string(surah_number));
QuranUrl.append(".mp3");
}

qurl = QuranUrl.c_str();
return qurl;
}

void Window::getSurah(std::string surah_name, std::string edition)
{
QDBReader Database;
Expand Down Expand Up @@ -161,13 +211,17 @@ void Window::getTranslation(std::string translation_name, std::string edition)
show_translation->setReadOnly(true);
}


void Window::showSurah()
{
QDBReader Database;
std::vector<std::string>data = Database.metadata();
surah_number = surah->currentIndex();
getSurah(data.at(surah_number), "quran");
getTranslation(data.at(surah_number), translation->currentText().toStdString());
QuranUrl = getQuranUrl(surah->currentIndex()+1);
player->stop();
player->setMedia(QuranUrl);
}

void Window::showTranslation()
Expand All @@ -194,8 +248,9 @@ void Window::showAbout()
QLabel *header = new QLabel("A Project by Muslim Programmers Community");
QLabel *Discord = new QLabel("Discord : discord.gg/7cnWVc8qgb");
QLabel *Instagram = new QLabel("Instagram : @muslimpgmrs");
QLabel *Contributers = new QLabel("Contributers : Nashid , Jonas , Bilal");
QLabel *footer = new QLabel("www.muslimprogrammers.com");
QLabel *Contributers = new QLabel("Contributers : Nashid , Jonas");
QLabel *footer = new QLabel("https://www.muslimprogrammers.com");
QLabel *version = new QLabel("Version 1.4 beta");
icon->setPixmap(pixmap);
icon->setAlignment(Qt::AlignCenter);
icon->setGeometry(QRect(312, 454, 21, 20));
Expand All @@ -214,12 +269,15 @@ void Window::showAbout()
footer->setFont(ffont);
footer->setAlignment(Qt::AlignCenter);
footer->setTextInteractionFlags(Qt::TextSelectableByMouse);
version->setFont(nfont);
version->setAlignment(Qt::AlignCenter);
layout->addWidget(icon);
layout->addWidget(header);
layout->addWidget(Discord);
layout->addWidget(Instagram);
layout->addWidget(Contributers);
layout->addWidget(footer);
layout->addWidget(version);
AboutWindow->setLayout(layout);
AboutWindow->setMinimumSize(602,443);
AboutWindow->setWindowTitle("About");
Expand Down Expand Up @@ -366,7 +424,36 @@ void Window::getPrayerTimes()
temp.append(QString::fromStdString(result["data"]["timings"]["Sunset"].get<std::string>()));
sunset->setText(temp);
} catch(nlohmann::json::type_error &err) {
QMessageBox::critical(PrayerTimeWidget, "Error", "Make sure you have connected to internet and entered a valid location");

QMessageBox::critical(PrayerTimeWidget, "Error", "Make sure you have connected to internet and entered a valid location , or maybe the API is down");
std::cerr << err.what() << std::endl;
}
}

void Window::set_play()
{
if(!quran_is_playing || quran_is_paused)
{
player->play();
quran_is_playing = true;
}
}

void Window::set_pause()
{
if(quran_is_playing)
{
player->pause();
quran_is_paused = true;
quran_is_playing = false;
}
}

void Window::set_stop()
{
if(quran_is_playing || quran_is_paused)
{
player->stop();
quran_is_playing = false;
quran_is_paused = false;
}
}
16 changes: 16 additions & 0 deletions src/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include <QTime>
#include <QDate>
#include <QGridLayout>
#include <QUrl>
#include <QtMultimedia/QtMultimedia>
#include <QProgressBar>
#include "curl_parser.hpp"
#include "db_reader.hpp"

Expand All @@ -37,8 +40,12 @@ class Window : public QMainWindow , public CURLParser
private:
int surah_number = 0;
bool dark_mode_enabled = false;
bool quran_is_playing = false;
bool quran_is_paused = true;
QUrl QuranUrl = "https://server8.mp3quran.net/afs/001.mp3";
QGroupBox *createComboBox();
QGroupBox *createTextBox();
QGroupBox *createPlayerUi();
void createMenu();
QComboBox *surah;
QComboBox *translation;
Expand All @@ -64,8 +71,14 @@ class Window : public QMainWindow , public CURLParser
QLineEdit *City;
QPushButton *Show;
QWidget *PrayerTimeWidget;
QWidget *MediaPlayerWidget;
QMediaPlayer *player;
QPushButton *play;
QPushButton *pause;
QPushButton *stop;
void getSurah(std::string, std::string);
void getTranslation(std::string, std::string);
QUrl getQuranUrl(int surah_number);
private slots:
void showSurah();
void showTranslation();
Expand All @@ -74,6 +87,9 @@ class Window : public QMainWindow , public CURLParser
void showTime();
void showPrayerTimes();
void getPrayerTimes();
void set_play();
void set_pause();
void set_stop();
};

#endif

0 comments on commit 99d9e16

Please sign in to comment.