Commit 4b2b8a4e authored by Roland Singer's avatar Roland Singer

removed Qt dependency

parent ab868f6a
*~
*.pro.user
CMakeLists.txt.user
build
build-debug
cmake_minimum_required(VERSION 2.8)
project(manjaro-web-repo)
SET (CMAKE_INSTALL_PREFIX "/usr/")
SET (WT_CONNECTOR "wthttp" CACHE STRING "Connector used (wthttp or wtfcgi)")
add_definitions(-std=c++11 -Wall)
add_subdirectory(src)
add_subdirectory(data)
INSTALL(DIRECTORY "style"
DESTINATION "share/${PROJECT_NAME}"
)
# Boost
find_package(Boost COMPONENTS system filesystem thread signals random regex program_options date_time REQUIRED)
# Wt
SET(WT_LIBRARIES wt)
SET(WT_INCLUDE_DIR /usr/include/Wt)
# Curl
SET(CURL_LIBRARIES curl)
SET(CURL_INCLUDE_DIR /usr/include/curl)
# Project
include_directories(${Boost_INCLUDE_DIR} ${WT_INCLUDE_DIR} ${CURL_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
aux_source_directory(. SRC_FILES)
add_executable(${PROJECT_NAME} ${SRC_FILES})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} ${WT_CONNECTOR} ${WT_LIBRARIES} ${CURL_LIBRARIES})
This diff is collapsed.
......@@ -23,14 +23,19 @@
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <boost/thread.hpp>
#include <QString>
#include <QList>
#include <QMap>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <WDateTime>
#include "const.h"
#include "global.h"
using namespace std;
using namespace Wt;
......@@ -47,8 +52,8 @@ private:
void run();
void updateRepositoryStateList();
long getRepoLastSync(const QString & url, const QDateTime & currentDateTime);
Global::STATE getRepoBranchState(const QString & url, const QString & currentBranchHashState);
long getRepoLastSync(const string & url, const WDateTime & currentDateTime);
Global::STATE getRepoBranchState(const string & url, const string & currentBranchHashState);
};
#endif // BACKGROUNDWORKER_H
......@@ -21,14 +21,9 @@
#include "global.h"
#include <iostream>
#include <QMutexLocker>
#include <Wt/WStandardItem>
QMutex Global::repoStatesMutex;
QList<Global::RepoState> Global::repoStates;
boost::mutex Global::repoStatesMutex;
vector<Global::RepoState> Global::repoStates;
......@@ -45,16 +40,16 @@ void Global::cleanup() {
QList<Global::RepoState> Global::getRepoStates() {
QMutexLocker locker(&repoStatesMutex);
vector<Global::RepoState> Global::getRepoStates() {
boost::lock_guard<boost::mutex> lock(repoStatesMutex);
return repoStates;
}
void Global::setRepoStates(const QList<Global::RepoState> & repoStates) {
QMutexLocker locker(&repoStatesMutex);
void Global::setRepoStates(const vector<Global::RepoState> & repoStates) {
boost::lock_guard<boost::mutex> lock(repoStatesMutex);
Global::repoStates.clear();
Global::repoStates = repoStates;
......@@ -62,9 +57,33 @@ void Global::setRepoStates(const QList<Global::RepoState> & repoStates) {
std::string Global::getWebContent(const std::string & url)
bool Global::executeCommand(const string & cmd, const string & workingDir) {
int fd = open(".", O_RDONLY);
if (fd < 0) {
cerr << "error: failed to open fd!" << endl;
return false;
}
if (chdir(workingDir.c_str()) != 0) {
cerr << "error: failed to chdir!" << endl;
return false;
}
int ret = system(cmd.c_str());
if (fchdir(fd) != 0) {
cerr << "error: failed to fchdir!" << endl;
return false;
}
return WEXITSTATUS(ret) == 0;
}
string Global::getWebContent(const string & url)
{
std::ostringstream oss;
ostringstream oss;
if(CURLE_OK == curl_read(url, oss))
return oss.str();
......@@ -84,8 +103,8 @@ size_t Global::data_write(void* buf, size_t size, size_t nmemb, void* userp)
{
if(userp)
{
std::ostream& os = *static_cast<std::ostream*>(userp);
std::streamsize len = size * nmemb;
ostream& os = *static_cast<ostream*>(userp);
streamsize len = size * nmemb;
if(os.write(static_cast<char*>(buf), len))
return len;
}
......@@ -95,7 +114,7 @@ size_t Global::data_write(void* buf, size_t size, size_t nmemb, void* userp)
CURLcode Global::curl_read(const std::string& url, std::ostream& os, long timeout)
CURLcode Global::curl_read(const string & url, ostream& os, long timeout)
{
CURLcode code(CURLE_FAILED_INIT);
CURL* curl = curl_easy_init();
......
......@@ -22,27 +22,26 @@
#ifndef GLOBAL_H
#define GLOBAL_H
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <sstream>
#include <curl/curl.h>
#include <fcntl.h>
#include <unistd.h>
#include <curl.h>
#include <boost/thread.hpp>
#include <QString>
#include <QList>
#include <QStringList>
#include <QMap>
#include <QProcess>
#include <QDir>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QMutex>
#include <WStandardItemModel>
#include <WStandardItem>
#include <Wt/WStandardItemModel>
#include "const.h"
using namespace std;
using namespace Wt;
......@@ -52,25 +51,26 @@ public:
enum STATE { STATE_UP_TO_DATE, STATE_OUT_OF_DATE, STATE_UNKOWN };
struct RepoState {
QString url, country, protocol;
string url, country, protocol;
long lastSync;
QMap<QString, STATE> states;
map<string, STATE> states;
};
static void init();
static void cleanup();
static QList<Global::RepoState> getRepoStates();
static void setRepoStates(const QList<Global::RepoState> & repoStates);
static vector<Global::RepoState> getRepoStates();
static void setRepoStates(const vector<Global::RepoState> & repoStates);
static std::string getWebContent(const std::string & url);
static bool executeCommand(const string & cmd, const string & workingDir);
static string getWebContent(const string & url);
private:
static QMutex repoStatesMutex;
static QList<RepoState> repoStates;
static boost::mutex repoStatesMutex;
static vector<RepoState> repoStates;
static size_t data_write(void* buf, size_t size, size_t nmemb, void* userp);
static CURLcode curl_read(const std::string& url, std::ostream& os, long timeout = 30);
static CURLcode curl_read(const string & url, ostream& os, long timeout = 30);
};
#endif // GLOBAL_H
......@@ -20,17 +20,17 @@
#include <iostream>
#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WHBoxLayout>
#include <Wt/WBootstrapTheme>
#include <Wt/WCssTheme>
#include <WApplication>
#include <WEnvironment>
#include <WHBoxLayout>
#include <WBootstrapTheme>
#include <WCssTheme>
#include "global.h"
#include "mainwidget.h"
#include "backgroundworker.h"
using namespace std;
using namespace Wt;
......@@ -40,9 +40,9 @@ WApplication *createApplication(const WEnvironment& env)
Wt::WApplication* app = new Wt::WApplication(env);
if (app->appRoot().empty())
std::cerr << "warning: the approot looks suspect!" << std::endl;
cerr << "warning: the approot looks suspect!" << endl;
const std::string *theme = env.getParameter("theme");
const string *theme = env.getParameter("theme");
if (theme)
app->setTheme(new Wt::WCssTheme(*theme));
else
......
......@@ -20,12 +20,12 @@
#include "mainwidget.h"
#include <Wt/WHBoxLayout>
#include <Wt/WMenu>
#include <Wt/WNavigationBar>
#include <Wt/WStackedWidget>
#include <Wt/WText>
#include <Wt/WVBoxLayout>
#include <WHBoxLayout>
#include <WMenu>
#include <WNavigationBar>
#include <WStackedWidget>
#include <WText>
#include <WVBoxLayout>
#include "repositorystatepage.h"
......
......@@ -21,7 +21,7 @@
#ifndef MAINWIDGET_H
#define MAINWIDGET_H
#include <Wt/WContainerWidget>
#include <WContainerWidget>
using namespace Wt;
......
#-------------------------------------------------
#
# Project created by QtCreator 2013-05-26T15:43:49
#
#-------------------------------------------------
QT += core
QT -= gui
QMAKE_CXXFLAGS += -std=c++11
TARGET = manjaro-web-repo
LIBS += -L/usr/lib -lcurl -lboost_thread -lboost_system -lboost_signals -lwt -lwthttp
CONFIG += console
CONFIG -= app_bundl
CONFIG += no_keywords
TEMPLATE = app
SOURCES += main.cpp \
mainwidget.cpp \
repositorystatepage.cpp \
global.cpp \
backgroundworker.cpp
HEADERS += \
mainwidget.h \
repositorystatepage.h \
global.h \
backgroundworker.h \
const.h
target.path = /usr/bin
This diff is collapsed.
......@@ -53,8 +53,14 @@ RepositoryStatePage::RepositoryStatePage() :
void RepositoryStatePage::updateRepositoryStates() {
const QStringList branches = QString(REPO_BRANCHES).split(' ', QString::SkipEmptyParts);
const QList<Global::RepoState> repoStates = Global::getRepoStates();
// Get branches
vector<string> branches;
boost::split(branches, REPO_BRANCHES, boost::is_any_of(" "), boost::token_compress_on);
// Get repo states
const vector<Global::RepoState> repoStates = Global::getRepoStates();
// Clear model
model->clear();
/*
......@@ -67,33 +73,33 @@ void RepositoryStatePage::updateRepositoryStates() {
model->setHeaderData(++headerColumn, Wt::Horizontal, WString("Protocol"));
model->setHeaderData(++headerColumn, Wt::Horizontal, WString("Last sync (hh:mm)"));
for (int x = 0; x < branches.size(); x++) {
for (unsigned int x = 0; x < branches.size(); x++) {
model->insertColumns(++headerColumn, 1);
model->setHeaderData(headerColumn, Wt::Horizontal, WString(branches.at(x).toStdString()));
model->setHeaderData(headerColumn, Wt::Horizontal, WString(branches.at(x)));
}
/*
* Set repo content
*/
for (int i = 0; i < repoStates.size(); i++) {
for (unsigned int i = 0; i < repoStates.size(); i++) {
const Global::RepoState *repo = &repoStates.at(i);
int column = 0;
// Mirror
WStandardItem *mirrorItem = new WStandardItem(repo->url.toStdString());
WStandardItem *mirrorItem = new WStandardItem(repo->url);
model->setItem(i, column, mirrorItem);
// Country
WStandardItem *item = new WStandardItem(repo->country.toStdString());
WStandardItem *item = new WStandardItem(repo->country);
model->setItem(i, ++column, item);
// Protocol
item = new WStandardItem(repo->protocol.toStdString());
item = new WStandardItem(repo->protocol);
model->setItem(i, ++column, item);
// Last sync
item = new WStandardItem(minutesToString(repo->lastSync).toStdString());
item = new WStandardItem(minutesToString(repo->lastSync));
if (repo->lastSync >= 1440 && repo->lastSync < 2880) { // 1 day
item->setStyleClass("tableView_orange");
......@@ -107,8 +113,13 @@ void RepositoryStatePage::updateRepositoryStates() {
model->setItem(i, ++column, item);
for (int x = 0; x < branches.size(); x++) {
const Global::STATE state = repo->states.value(branches.at(i), Global::STATE_UNKOWN);
for (unsigned int x = 0; x < branches.size(); x++) {
const string branch = branches.at(i);
Global::STATE state = Global::STATE_UNKOWN;
if (repo->states.find(branch) != repo->states.end() )
state = repo->states.at(branch);
item = new WStandardItem("unknown");
......@@ -137,7 +148,7 @@ void RepositoryStatePage::updateRepositoryStates() {
tableView->setColumnWidth(++column, 100);
tableView->setColumnWidth(++column, 150);
for (int i = 0; i < branches.size(); i++)
for (unsigned int i = 0; i < branches.size(); i++)
tableView->setColumnWidth(++column, 100);
tableView->setWidth(828 + 107 * branches.size());
......@@ -145,14 +156,14 @@ void RepositoryStatePage::updateRepositoryStates() {
QString RepositoryStatePage::minutesToString(long minutes) {
string RepositoryStatePage::minutesToString(long minutes) {
if (minutes < 0)
return "unknown";
const int hours = minutes / 60;
minutes -= hours * 60;
return QString("%1:%2").arg(QString::number(hours), QString::number(minutes));
return to_string(hours) + ":" + to_string(minutes);
}
......
......@@ -21,19 +21,23 @@
#ifndef REPOSITORYSTATEPAGE_H
#define REPOSITORYSTATEPAGE_H
#include <QString>
#include <Wt/WString>
#include <Wt/WContainerWidget>
#include <Wt/WApplication>
#include <Wt/WStandardItemModel>
#include <Wt/WTableView>
#include <Wt/WStandardItemModel>
#include <Wt/WStandardItem>
#include <Wt/WPushButton>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <WString>
#include <WContainerWidget>
#include <WApplication>
#include <WStandardItemModel>
#include <WTableView>
#include <WStandardItemModel>
#include <WStandardItem>
#include <WPushButton>
#include "global.h"
using namespace Wt;
using namespace std;
class RepositoryStatePage : public WContainerWidget
......@@ -47,7 +51,7 @@ private:
Wt::WPushButton *buttonRefresh;
void updateRepositoryStates();
QString minutesToString(long minutes);
string minutesToString(long minutes);
void buttonRefresh_clicked();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment