Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion aboutdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@
<string>Vladislav Kobzar
-------------------
Ilya Spivakov
Matvey Adzhigirey</string>
Matvey Adzhigirey
Stefan Slonevskiy</string>
</property>
</widget>
</item>
Expand Down
23 changes: 12 additions & 11 deletions bible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,20 @@ Verse Bible::getCurrentVerseAndCaption(QList<int> currentRows, BibleSettings& s
Verse v;

// get primary verse
getVerseAndCaption(v.primary_text,v.primary_caption,verse_id,bv.primaryBible,sets.useAbbriviation);
getVerseAndCaption(v.primary_text,v.primary_caption,v.primary_abbr,verse_id,bv.primaryBible,sets.useAbbriviation);

// get secondary verse
if(bv.primaryBible!=bv.secondaryBible && bv.secondaryBible!="none")
getVerseAndCaption(v.secondary_text,v.secondary_caption,verse_id,bv.secondaryBible,sets.useAbbriviation);
getVerseAndCaption(v.secondary_text,v.secondary_caption,v.secondary_abbr,verse_id,bv.secondaryBible,sets.useAbbriviation);

// get trinary versse
if(bv.trinaryBible!=bv.primaryBible && bv.trinaryBible!=bv.secondaryBible && bv.trinaryBible!="none")
getVerseAndCaption(v.trinary_text,v.trinary_caption,verse_id,bv.trinaryBible,sets.useAbbriviation);
getVerseAndCaption(v.trinary_text,v.trinary_caption,v.trinary_abbr,verse_id,bv.trinaryBible,sets.useAbbriviation);

return v;
}

void Bible::getVerseAndCaption(QString& verse, QString& caption, QString verId, QString& bibId, bool useAbbr)
void Bible::getVerseAndCaption(QString& verse, QString& caption, QString& abbr, QString verId, QString& bibId, bool useAbbr)
{
QString verse_old, verse_show, verse_n, verse_nold, verse_nfirst, chapter;
QString book;
Expand Down Expand Up @@ -280,18 +280,19 @@ void Bible::getVerseAndCaption(QString& verse, QString& caption, QString verId,
caption = sq.value(0).toString() + caption;
sq.clear();

// Add bible abbreveation if to to use it
if(useAbbr)
{
sq.exec("SELECT abbreviation FROM BibleVersions WHERE id = " + bibId);
sq.first();
QString abr = sq.value(0).toString().trimmed();
if (!abr.isEmpty())
// Add bible abbreviation if to to use it
sq.exec("SELECT abbreviation FROM BibleVersions WHERE id = " + bibId);
sq.first();
QString abr = sq.value(0).toString().trimmed();
if (!abr.isEmpty()) {
abbr = QString("%1").arg(abr);
if (useAbbr)
caption = QString("%1 (%2)").arg(caption).arg(abr);
}

verse = verse.simplified();
caption = caption.simplified();
abbr = abbr.simplified();
}

QList<BibleSearch> Bible::searchBible(bool allWords, QRegExp searchExp)
Expand Down
7 changes: 5 additions & 2 deletions bible.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ class Verse
// For now both primary and secondary information is stored in
// primary_text and primary_caption
QString primary_text;
QString secondary_text;
QString primary_caption;
QString primary_abbr;
QString secondary_text;
QString secondary_caption;
QString secondary_abbr;
QString trinary_text;
QString trinary_caption;
QString trinary_abbr;
};

class BibleSearch
Expand Down Expand Up @@ -96,7 +99,7 @@ public slots:
void getVerseRef(QString vId, QString &book, int &chapter, int &verse);
int getVerseNumberLast(QString vId);
QStringList getChapter(int book, int chapter);
void getVerseAndCaption(QString &verse, QString &caption, QString verId, QString &bibId, bool useAbbr);
void getVerseAndCaption(QString& verse, QString& caption, QString& abbr, QString verId, QString& bibId, bool useAbbr);
int getCurrentBookRow(QString book);
Verse getCurrentVerseAndCaption(QList<int> currentRows, BibleSettings& sets, BibleVersionSettings& bv);
void setBiblesId(QString& id);
Expand Down
2 changes: 1 addition & 1 deletion biblewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void BibleWidget::on_search_button_clicked()

if (!search_results.isEmpty()) // If have results, then show them
{
if( not ui->result_label->isVisible() )
if( !ui->result_label->isVisible() )
{
ui->lineEditBook->clear();
hidden_splitter_state = ui->results_splitter->saveState();
Expand Down
9 changes: 8 additions & 1 deletion generalsettingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void GeneralSettingWidget::loadSettings()
loadThemes();
ui->comboBoxTheme->setCurrentIndex(themeIdList.indexOf(mySettings.currentThemeId));

// Get display screen infomration
// Get display screen information
monitors.clear();
QDesktopWidget d;
int screen_count = d.screenCount();
Expand Down Expand Up @@ -101,6 +101,10 @@ void GeneralSettingWidget::loadSettings()
ui->comboBoxControlsAlignV->setCurrentIndex(mySettings.displayControls.alignmentV);
ui->comboBoxControlsAlignH->setCurrentIndex(mySettings.displayControls.alignmentH);
ui->horizontalSliderOpacity->setValue(mySettings.displayControls.opacity*100);

// Set HTTP Controls
ui->checkBoxEnableHttpServer->setChecked(mySettings.httpServerEnabled);
ui->lineEditHttpPort->setText(QString::number(mySettings.httpServerPort));
}

void GeneralSettingWidget::loadThemes()
Expand Down Expand Up @@ -139,6 +143,9 @@ GeneralSettings GeneralSettingWidget::getSettings()
r = r/100;
mySettings.displayControls.opacity = r;

mySettings.httpServerEnabled = ui->checkBoxEnableHttpServer->isChecked();
mySettings.httpServerPort = ui->lineEditHttpPort->text().toInt();

return mySettings;
}

Expand Down
52 changes: 52 additions & 0 deletions generalsettingwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,58 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxHttpControls">
<property name="title">
<string>HTTP XML Feed Controls</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditHttpPort">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_HttpPort">
<property name="text">
<string>HTTP Server Port:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxEnableHttpServer">
<property name="text">
<string>Enable HTTP XML feed</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
140 changes: 140 additions & 0 deletions httpserver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/***************************************************************************
//
// softProjector - an open source media projection software
// Copyright (C) 2021 Vladislav Kobzar
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
***************************************************************************/

#include "httpserver.hpp"

HttpServer::HttpServer(QObject *parent) : QObject(parent)
{
isRunning = false;
}

HttpServer::~HttpServer()
{
stopServer();
}

void HttpServer::startServer(quint16 port)
{
server = new QTcpServer(this);

// waiting for the web brower to make contact, this will emit signal
connect(server, SIGNAL(newConnection()), this, SLOT(startConnection()));

if(!server->listen(QHostAddress::Any, port))
isRunning = false;
else
isRunning = true;
}

void HttpServer::startConnection()
{
QTcpSocket *socket = server->nextPendingConnection();
connect(socket, SIGNAL(readyRead()), this, SLOT(sendData()));
connect(socket, SIGNAL(disconnected()), this, SLOT(closingClient()));
}

void HttpServer::closingClient()
{
QTcpSocket* socket = (QTcpSocket*)sender();
socket->deleteLater();
}

void HttpServer::sendData()
{
QTcpSocket* socket = (QTcpSocket*)sender();

socket->write("HTTP/1.1 200 OK\r\n"); // \r needs to be before \n
socket->write("Content-Type: text/xml\r\n");
socket->write("Connection: close\r\n"); // Require two \r\n.
socket->write("\r\n");

socket->write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
socket->write("<softprojector>\r\n");
socket->write(xmlData.toUtf8());
socket->write("</softprojector>\r\n");

socket->disconnectFromHost();
}


void HttpServer::stopServer()
{
server->close();
delete server;
isRunning = false;
}

void HttpServer::setBibleText(Verse bVerse, BibleSettings &bSets)
{
// Translation flags
bool havePrimary = ("none" != bSets.versions.primaryBible);
bool haveSecondary = ("none" != bSets.versions.secondaryBible);
bool haveTrinary = ("none" != bSets.versions.trinaryBible);

xmlData = "";

xmlData += "<bible class=\"primary\">\r\n";
xmlData += "<verse>" + bVerse.primary_text + "</verse>\r\n";
xmlData += "<reference>" + bVerse.primary_caption + "</reference>\r\n";
xmlData += "<translation>" + bVerse.primary_abbr + "</translation>\r\n";
xmlData += "</bible>\r\n";

if (haveSecondary) {
xmlData += "<bible class=\"secondary\">\r\n";
xmlData += "<verse>" + bVerse.secondary_text + "</verse>\r\n";
xmlData += "<reference>" + bVerse.secondary_caption + "</reference>\r\n";
xmlData += "<translation>" + bVerse.secondary_abbr + "</translation>\r\n";
xmlData += "</bible>\r\n";
}

if (haveTrinary) {
xmlData += "<bible class=\"tertiary\">\r\n";
xmlData += "<verse>" + bVerse.trinary_text + "</verse>\r\n";
xmlData += "<reference>" + bVerse.trinary_caption + "</reference>\r\n";
xmlData += "<translation>" + bVerse.trinary_abbr + "</translation>\r\n";
xmlData += "</bible>\r\n";
}
}

void HttpServer::setSongText(Stanza stanza, SongSettings &sSets)
{
xmlData = "<song>\r\n";

xmlData += "<stanza>" + stanza.stanza + "</stanza>\r\n";
xmlData += "<title>" + stanza.stanzaTitle + "</title>\r\n";
xmlData += "<tune>" + stanza.tune + "</tune>\r\n";
xmlData += "<words_by>" + stanza.wordsBy + "</words_by>\r\n";
xmlData += "<music_by>" + stanza.musicBy + "</music_by>\r\n";
xmlData += "<number>" + QString::number(stanza.number) + "</number>\r\n";
xmlData += "<is_last>" + QString::number(stanza.isLast) + "</is_last>\r\n";

xmlData += "</song>\r\n";
}

void HttpServer::setAnnounceText(AnnounceSlide announce, TextSettings &aSets)
{
xmlData = "<announcement>\r\n";
xmlData += "<text>" + announce.text + "</text>\r\n";
xmlData += "</announcement>\r\n";
}

void HttpServer::setBlank()
{
xmlData = "";
}
68 changes: 68 additions & 0 deletions httpserver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/***************************************************************************
//
// softProjector - an open source media projection software
// Copyright (C) 2021 Vladislav Kobzar
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
***************************************************************************/

// Simple HTTP server implementation in Qt taken from https://stackoverflow.com/a/32931195

#ifndef HTTPSERVER_HPP
#define HTTPSERVER_HPP

#include <QCoreApplication>
#include <QNetworkInterface>
#include <iostream>
#include <QObject>
#include <QTcpSocket>
#include <QTcpServer>
#include <QDebug>

#include "bible.hpp"
#include "song.hpp"
#include "announcement.hpp"

class HttpServer : public QObject
{
Q_OBJECT

public:
explicit HttpServer(QObject *parent = 0);
~HttpServer();
void startServer(quint16 port);
void stopServer();
void setBibleText(Verse bVerse, BibleSettings &bSets);
void setSongText(Stanza stanza, SongSettings &sSets);
void setAnnounceText(AnnounceSlide announce, TextSettings &aSets);
void setBlank();
bool isRunning;
//QTcpSocket *socket;

public slots:
void startConnection();
void sendData();
void closingClient();

private:
QTcpServer *server;
qint64 bytesAvailable() const;
QString xmlData;
void establishConnection();
bool servingConnection;

signals:
};

#endif
Loading