diff --git a/CMakeLists.txt b/CMakeLists.txt index 40f6357..bf445c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ 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) @@ -7,7 +7,7 @@ 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 @@ -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) diff --git a/src/main.cpp b/src/main.cpp index e9f8459..4ff7bfa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,7 @@ * 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 * ***/ @@ -10,18 +10,8 @@ #include #include #include -#include -#include -#include -#include #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 diff --git a/src/window.cpp b/src/window.cpp index c4ae8e3..e0249d0 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -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() @@ -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())); @@ -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; @@ -161,6 +211,7 @@ void Window::getTranslation(std::string translation_name, std::string edition) show_translation->setReadOnly(true); } + void Window::showSurah() { QDBReader Database; @@ -168,6 +219,9 @@ void Window::showSurah() 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() @@ -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)); @@ -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"); @@ -366,7 +424,36 @@ void Window::getPrayerTimes() temp.append(QString::fromStdString(result["data"]["timings"]["Sunset"].get())); 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; + } +} \ No newline at end of file diff --git a/src/window.hpp b/src/window.hpp index e0d3334..9c07dae 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -26,6 +26,9 @@ #include #include #include +#include +#include +#include #include "curl_parser.hpp" #include "db_reader.hpp" @@ -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; @@ -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(); @@ -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