Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New cups backend based on D-Bus.

  • Loading branch information...
commit bd02cff2fb0c16137dae2bafc1e9739376703b28 1 parent 2729936
@SokoloffA SokoloffA authored
View
55 CMakeLists.txt
@@ -2,22 +2,73 @@ cmake_minimum_required( VERSION 2.6 )
project(boomaga)
+# Linux ***************************************
+if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+
+ set(DEF_CUPS_BACKEND_DIR /usr/lib/cups/backend)
+ set(DEF_CUPS_PPD_DIR /usr/share/ppd/boomaga)
+ set(DEF_DBUS_MACINE_ID_DIR /var/lib/dbus)
+ set(DEF_DBUS_SERVICE_DIR ${CMAKE_INSTALL_PREFIX}/share/dbus-1/services)
+
+# FreeBSD *************************************
+elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
+
+ set(DEF_CUPS_BACKEND_DIR /usr/local/libexec/cups/backend)
+ set(DEF_CUPS_PPD_DIR /usr/local/share/cups/model)
+ set(DEF_DBUS_MACINE_ID_DIR /var/db/dbus)
+ set(DEF_DBUS_SERVICE_DIR ${CMAKE_INSTALL_PREFIX}/share/dbus-1/services)
+
+endif()
+
set(GUI_DIR ${CMAKE_INSTALL_PREFIX}/lib/boomaga)
add_definitions(-DGUI_DIR=\"${GUI_DIR}\")
+
set(GUI_PROGRAM ${GUI_DIR}/boomaga)
add_definitions(-DGUI_PROGRAM=\"${GUI_PROGRAM}\")
+
set(CUPS_BACKEND_URI "boomaga:/")
add_definitions(-DCUPS_BACKEND_URI=\"${CUPS_BACKEND_URI}\")
+
+set(CUPS_BACKEND_INFO "Boomaga")
+add_definitions(-DCUPS_BACKEND_INFO=\"${CUPS_BACKEND_NAME}\")
+
+
+set(CUPS_BACKEND_MODEL "Virtual boomaga printer")
+add_definitions(-DCUPS_BACKEND_MODEL=\"${CUPS_BACKEND_MODEL}\")
+
+
set(CUPS_BACKEND_MANUFACTURER "Generic")
add_definitions(-DCUPS_BACKEND_MANUFACTURER=\"${CUPS_BACKEND_MANUFACTURER}\")
-set(CUPS_BACKEND_MODEL "Boomaga Printer")
-add_definitions(-DCUPS_BACKEND_MODEL=\"${CUPS_BACKEND_MODEL}\")
+
+
+###########################################################
+
+macro(setByDefault VAR_NAME VAR_VALUE)
+ if (NOT DEFINED ${VAR_NAME})
+ set (${VAR_NAME} ${VAR_VALUE})
+ add_definitions(-D${VAR_NAME}=\"${VAR_VALUE}\")
+ endif()
+endmacro()
+
+setByDefault(CUPS_BACKEND_DIR ${DEF_CUPS_BACKEND_DIR})
+setByDefault(CUPS_PPD_DIR ${DEF_CUPS_PPD_DIR})
+setByDefault(DBUS_MACINE_ID_DIR ${DEF_DBUS_MACINE_ID_DIR})
+setByDefault(DBUS_SERVICE_DIR ${DEF_DBUS_SERVICE_DIR})
add_subdirectory(cups)
add_subdirectory(gui)
+message(STATUS "*****************************************************")
+message(STATUS "** You can change next directories using cmake options like.")
+message(STATUS "* cmake -DCUPS_BACKEND_DIR=your_path")
+message(STATUS "*")
+message(STATUS "* CUPS_BACKEND_DIR = ${CUPS_BACKEND_DIR}")
+message(STATUS "* CUPS_PPD_DIR = ${CUPS_PPD_DIR}")
+message(STATUS "* DBUS_MACINE_ID_DIR = ${DBUS_MACINE_ID_DIR}")
+message(STATUS "* DBUS_SERVICE_DIR = ${DBUS_SERVICE_DIR}")
+message(STATUS "*****************************************************")
View
4 cups/CMakeLists.txt
@@ -15,11 +15,11 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/boomaga.ppd
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/boomaga
- DESTINATION /usr/lib/cups/backend
+ DESTINATION ${CUPS_BACKEND_DIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/boomaga.ppd
- DESTINATION /usr/share/ppd/boomaga
+ DESTINATION ${CUPS_PPD_DIR}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
View
87 cups/boomaga
@@ -10,8 +10,10 @@ CUPS_BACKEND_FAILED=1
# Output "device discovery" information on stdout:
# http://www.cups.org/documentation.php/doc-1.6/man-backend.html
-if test "$#" = "0"; then
- echo "file @CUPS_BACKEND_URI@ \"@CUPS_BACKEND_MANUFACTURER@ @CUPS_BACKEND_MODEL@\" \"@CUPS_BACKEND_MANUFACTURER@ @CUPS_BACKEND_MODEL@\" \"@CUPS_BACKEND_ID@\""
+# device-class device-uri "device-make-and-model" "device-info" "device-id"
+if test "$#" = "0";
+then
+ echo "file @CUPS_BACKEND_URI@ \"@CUPS_BACKEND_MODEL@\" \"@CUPS_BACKEND_INFO@\" \"@CUPS_BACKEND_ID@\""
exit 0
fi
@@ -22,27 +24,31 @@ count=$4
options=$5
psFile=$6
-if [ -z ${psFile} ]; then
- psFile=${TMP_DIR}/brint_in_file-${jobID}.ps
+if [ -z ${psFile} ];
+then
+ psFile=${TMP_DIR}/boomaga_in_file-${jobID}.ps
cat - > ${psFile}
fi
+chown ${user} ${psFile}
uid=$(getent passwd ${user} | cut -d':' -f 3)
homeDir=$(getent passwd ${user} | cut -d':' -f 6)
-if [ "${uid}" == "" ]; then
+if [ "${uid}" == "" ];
+then
echo "ERROR: Can't found UID for user '${user}'" >&2
exit $CUPS_BACKEND_FAILED
fi
-if [ "${homeDir}" == "" ]; then
+if [ "${homeDir}" == "" ];
+then
echo "ERROR: Can't found home directory for user '$user' (UID: $uid)" >&2
exit $CUPS_BACKEND_FAILED
fi
-echo "DEBUG: User $user" >&2
-echo "DEBUG: Uid $uid" >&2
+echo "DEBUG: User: $user" >&2
+echo "DEBUG: Uid: $uid" >&2
oldIfs=$IFS
IFS=$(echo -en "\n")
@@ -52,10 +58,8 @@ while read line; do
case $key in
Session*)
- if [ "$sesUid" = "$uid" -a "$sesActive" = "TRUE" -a "$sesDisplay" != "" ]; then
- echo "DEBUG: Session=$line" >&2
- echo "DEBUG: DISPLAY=$sesDisplay" >&2
-
+ if [ "$sesUid" = "$uid" -a "$sesActive" = "TRUE" -a "$sesDisplay" != "" ];
+ then
xDisplay=$sesDisplay
break;
fi
@@ -77,19 +81,62 @@ while read line; do
sesDisplay=$value
;;
esac
-done <<< $(ck-list-sessions | tac );
-
+done <<< $(ck-list-sessions; echo "SessionEnd:");
+IFS=${oldIfs}
+echo "DEBUG: xDisplay: ${xDisplay}" >&2
-if [ "${xDisplay}" == "" ]; then
+if [ "${xDisplay}" == "" ];
+then
echo "ERROR: Can't found session for user '$user' (UID: $uid)" >&2
exit $CUPS_BACKEND_FAILED
fi
-chown ${user} ${psFile}
-export DISPLAY=${xDisplay}
-export XAUTHORITY=${homeDir}/.Xauthority
-su -l -c "@GUI_PROGRAM@ -t \"$title\" -n $count $psFile" $user 0<&- &>/tmp/boomaga-${user}.log &
-exit $CUPS_BACKEND_OK
+# the X display without the screen number, with the following prefixes removed,
+# if present: ":", "localhost:" ."localhost.localdomain:". That is, a display
+# of "localhost:10.0" produces just the number "10"
+dbusDisplay=$(echo ${xDisplay} | cut -d ':' -f 2 | cut -d '.' -f 1)
+echo "DEBUG: dbusDisplay: ${dbusDisplay}" >&2
+if [ "${dbusDisplay}" == "" ];
+then
+ echo "ERROR: Can't extract D-Bus display num from '${xDisplay}' for user '$user' (UID: $uid)" >&2
+ exit $CUPS_BACKEND_FAILED
+fi
+echo "DEBUG: xDisplay: ${xDisplay}" >&2
+
+
+if [ ! -f "@DBUS_MACINE_ID_DIR@/machine-id" ];
+then
+ echo "ERROR: Dbus machine-id file '@DBUS_MACINE_ID_DIR@/machine-id' not found." >&2
+ exit $CUPS_BACKEND_FAILED
+fi
+
+
+dbusSessionFile=${homeDir}/.dbus/session-bus/$(cat "@DBUS_MACINE_ID_DIR@/machine-id")-${dbusDisplay}
+echo "DEBUG: dbusSessionFile: ${dbusSessionFile}" >&2
+if [ ! -f ${dbusSessionFile} ];
+then
+ echo "ERROR: Dbus session file '${dbusSessionFile}' not found." >&2
+ exit $CUPS_BACKEND_FAILED
+fi
+
+
+dbusSessionAddress=$(grep DBUS_SESSION_BUS_ADDRESS= ${dbusSessionFile} | cut -d "=" -f 2-)
+echo "DEBUG: dbusSessionAddress: ${dbusSessionAddress}" >&2
+if [ "${dbusSessionAddress}" == "" ];
+then
+ echo "ERROR: Can't extract D-Bus bus address from '${dbusSessionFile}' for user '$user' (UID: $uid)" >&2
+ exit $CUPS_BACKEND_FAILED
+fi
+
+
+cmd="dbus-send --session --type=method_call --print-reply --dest=org.boomaga /Project org.boomaga.addFile string:${psFile} "
+echo "DEBUG: command: ${cmd}" >&2
+
+errorLog="/tmp/boomaga_${jobID}.err"
+su -c "DBUS_SESSION_BUS_ADDRESS=${dbusSessionAddress} ${cmd}" ${user} 2>${errorLog} 1>/dev/null && exit $CUPS_BACKEND_OK
+
+cat ${errorLog} | sed -e"s/^/ERROR: /" 1>&2
+rm ${errorLog}
View
15 gui/CMakeLists.txt
@@ -91,17 +91,19 @@ set(CMAKE_BUILD_TYPE Debug)
#*******************************************
+SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+find_package(Qt4 REQUIRED)
+find_package(Ghostscript REQUIRED)
+
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/third-party
${CMAKE_CURRENT_SOURCE_DIR}/third-party/libspectre
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
+ ${GHOSTSCRIPT_INCLUDES}
)
-SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
-find_package(Qt4 REQUIRED)
-find_package(Ghostscript REQUIRED)
include(${QT_USE_FILE})
qt4_wrap_cpp(MOC_SOURCES ${MOCS})
@@ -113,9 +115,14 @@ qt4_add_translation(QM_FILES ${TS_FILES})
add_executable(boomaga ${HEADERS} ${SOURCES} ${MOC_SOURCES} ${QM_FILES} ${QRC_SOURCES} ${UI_HEADERS})
target_link_libraries(boomaga ${LIBRARIES} ${QT_LIBRARIES} ${GHOSTSCRIPT_LIBRARIES})
-install(FILES ${QM_FILES} DESTINATION ${TRANSLATIONS_DIR})
install(TARGETS boomaga RUNTIME DESTINATION ${GUI_DIR})
+install(FILES ${QM_FILES} DESTINATION ${TRANSLATIONS_DIR})
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/org.boomaga.service
+ ${CMAKE_CURRENT_BINARY_DIR}/org.boomaga.service
+ @ONLY)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.boomaga.service DESTINATION ${DBUS_SERVICE_DIR})
View
20 gui/kernel/psfile.cpp
@@ -38,6 +38,16 @@
/************************************************
************************************************/
+PsFilePos::PsFilePos()
+{
+ begin = 0;
+ end = 0;
+}
+
+
+/************************************************
+
+ ************************************************/
PsFilePage::PsFilePage(PsFile *file, const PsFilePos &pos, int pageNum):
mFile(file),
mPageNum(pageNum),
@@ -63,7 +73,6 @@ PsFile::PsFile(const QString &fileName, QObject *parent):
QObject(parent),
mFile(fileName)
{
- parse();
}
@@ -102,9 +111,12 @@ void PsFile::writeFilePart(long begin, long end, QTextStream *out)
if (!mFile.isOpen())
mFile.open(QIODevice::ReadOnly | QIODevice::Text);
- mFile.seek(begin);
- QByteArray buf = mFile.read(end - begin);
- *out << buf;
+ if (mFile.isOpen())
+ {
+ mFile.seek(begin);
+ QByteArray buf = mFile.read(end - begin);
+ *out << buf;
+ }
}
View
7 gui/kernel/psfile.h
@@ -36,8 +36,10 @@
class PsFile;
class QTextStream;
-struct PsFilePos
+class PsFilePos
{
+public:
+ PsFilePos();
long begin;
long end;
};
@@ -89,8 +91,9 @@ class PsFile : public QObject
void writePageBody(const PsFilePos &pos, QTextStream *out);
void writePageBody(long begin, long end, QTextStream *out);
-protected:
bool parse();
+
+protected:
QFile mFile;
QList<PsFilePage> mPages;
View
1  gui/kernel/psproject.cpp
@@ -72,6 +72,7 @@ void PsProject::addFile(QString fileName)
PsFile *file = new PsFile(fileName, this);
mFiles << file;
+ file->parse();
for (int i=0; i<file->pageCount(); ++i)
{
PsProjectPage *p = new PsProjectPage(file, i);
View
38 gui/main.cpp
@@ -36,12 +36,12 @@
#include <QFileInfo>
#include <QLibraryInfo>
#include <QDebug>
-
+#include <QProcessEnvironment>
void printHelp()
{
QTextStream out(stdout);
- out << "Usage: boomaga [options] file" << endl;
+ out << "Usage: boomaga [options] [file]" << endl;
out << endl;
out << "Print poscript file as booklet" << endl;
@@ -140,28 +140,36 @@ int main(int argc, char *argv[])
file.setFile(args.at(i));
}
- if (file.filePath().isEmpty())
- return printError("Postscript file missing.");
-
- if (!file.exists())
- return printError(QString("Cannot open file \"%1\" (No such file or directory)")
- .arg(file.filePath()));
- if (!file.isReadable())
- return printError(QString("Cannot open file \"%1\" (Access denied)")
- .arg(file.filePath()));
+ if (!file.filePath().isEmpty())
+ {
+ if (!file.exists())
+ return printError(QString("Cannot open file \"%1\" (No such file or directory)")
+ .arg(file.filePath()));
- // We try to open file in the another instanse (if it running).
- if (DBusProjectAdaptor::openFileInExisting(file.absoluteFilePath()))
- return 0;
+ if (!file.isReadable())
+ return printError(QString("Cannot open file \"%1\" (Access denied)")
+ .arg(file.filePath()));
+ }
+#if 0
+ QFile f(QString("/tmp/boomaga-%1.env").arg(QDateTime::currentDateTime().toString("yyyy.MM.dd-hh.mm.ss")));
+ f.open(QFile::WriteOnly | QFile::Text);
+ foreach(QString s, QProcessEnvironment::systemEnvironment().toStringList())
+ {
+ f.write(s.toLocal8Bit());
+ f.write("\n");
+ }
+ f.close();
+#endif
PsProject project;
DBusProjectAdaptor dbus(&project);
QDBusConnection::sessionBus().registerService("org.boomaga");
QDBusConnection::sessionBus().registerObject("/Project", &project);
- project.addFile(file.absoluteFilePath());
+ if (!file.filePath().isEmpty())
+ project.addFile(file.absoluteFilePath());
MainWindow mainWindow(&project);
mainWindow.show();
View
3  gui/org.boomaga.service
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.boomaga
+Exec=@GUI_PROGRAM@
Please sign in to comment.
Something went wrong with that request. Please try again.