Skip to content

Commit 3cf2f54

Browse files
Qt coding style
1 parent 71e0433 commit 3cf2f54

File tree

4 files changed

+87
-96
lines changed

4 files changed

+87
-96
lines changed

app/window.cpp renamed to app/QCPDialog.cpp

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
#include "window.h"
2-
3-
_Window *_window;
1+
#include "QCPDialog.h"
2+
#include <QGridLayout>
3+
#include <QQuickItem>
4+
#include "components.h"
5+
#include <CPD.h>
6+
7+
namespace {
8+
struct Command {
9+
std::string command;
10+
std::string arg1;
11+
std::string arg2;
12+
};
13+
QCPDialog *qcpdialog;
14+
}
415

5-
_Window::_Window(QPrinter *printer, QWidget *parent) :
6-
QWidget(parent),
16+
QCPDialog::QCPDialog(QPrinter *printer, QWidget *parent) :
17+
QAbstractPrintDialog (printer, parent),
718
tabs(new Tabs(this)),
819
root(new Root(this)),
920
preview(new Preview(printer, this)),
@@ -92,60 +103,44 @@ _Window::_Window(QPrinter *printer, QWidget *parent) :
92103
CPrintDialog::CPrintDialog(QPrinter *printer, QWidget *parent) :
93104
QAbstractPrintDialog(printer, parent)
94105
{
95-
_window = new _Window(printer, parent);
96-
_window->show();
106+
qcpdialog = new QCPDialog(printer, parent);
107+
qcpdialog->show();
97108
}
98109

99-
void _Window::tabBarIndexChanged(qint32 index)
110+
void QCPDialog::tabBarIndexChanged(qint32 index)
100111
{
101112
root->rootObject->setProperty("index", index);
102113
}
103114

104-
void _Window::swipeViewIndexChanged(qint32 index)
115+
void QCPDialog::swipeViewIndexChanged(qint32 index)
105116
{
106117
tabs->rootObject->setProperty("index", index);
107118
}
108119

109-
void _Window::cancelButtonClicked()
120+
void QCPDialog::cancelButtonClicked()
110121
{
111122
exit(0);
112123
}
113124

114125
static void add_printer_callback(PrinterObj *p)
115126
{
116127
//qDebug() << "Printer" << p->name << "added!";
117-
_window->addPrinter(p->name);
128+
qcpdialog->addPrinter(p->name);
118129
}
119130

120131
static void remove_printer_callback(char *printer_name)
121132
{
122133
qDebug() << "Printer" << printer_name << "removed! callback";
123134
}
124135

125-
gpointer _Window::ui_add_printer(gpointer user_data)
126-
{
127-
/*
128-
* Need this delay so that the FrontendObj
129-
* initialization completes
130-
*/
131-
bool *enabled = (bool *)user_data;
132-
for (int i = 0; i < 100000000; i++);
133-
Command cmd;
134-
if (*enabled)
135-
cmd.command = "unhide-remote-cups";
136-
else
137-
cmd.command = "hide-remote-cups";
138-
parse_commands(cmd);
139-
clearPrinters();
140-
g_hash_table_foreach(f->printer, ui_add_printer_aux, NULL);
141-
}
142-
143136
void ui_add_printer_aux(gpointer key, gpointer value, gpointer user_data)
144137
{
145-
_window->addPrinter(static_cast<const char *>(key));
138+
Q_UNUSED(value);
139+
Q_UNUSED(user_data);
140+
qcpdialog->addPrinter(static_cast<const char *>(key));
146141
}
147142

148-
void _Window::addPrinter(const char *printer)
143+
void QCPDialog::addPrinter(const char *printer)
149144
{
150145
QObject *obj = root->rootObject->findChild<QObject *>("generalObject");
151146
if (obj) {
@@ -156,16 +151,17 @@ void _Window::addPrinter(const char *printer)
156151
qDebug() << "generalObject Not Found";
157152
}
158153

159-
void _Window::parse_commands(Command cmd)
154+
void QCPDialog::parse_commands(gpointer user_data)
160155
{
161-
if (cmd.command.compare("hide-remote-cups") == 0)
156+
Command *cmd = (Command *)user_data;
157+
if (cmd->command.compare("hide-remote-cups") == 0)
162158
hide_remote_cups_printers(f);
163-
else if (cmd.command.compare("unhide-remote-cups") == 0)
159+
else if (cmd->command.compare("unhide-remote-cups") == 0)
164160
unhide_remote_cups_printers(f);
165-
else if (cmd.command.compare("get-all-options") == 0) {
161+
else if (cmd->command.compare("get-all-options") == 0) {
166162
char printerName[300];
167-
strcpy(printerName, cmd.arg1.c_str());
168-
Options *options = get_all_printer_options(_window->f, printerName, "CUPS");
163+
strcpy(printerName, cmd->arg1.c_str());
164+
Options *options = get_all_printer_options(qcpdialog->f, printerName, (char *)"CUPS");
169165
GHashTableIter iterator;
170166
g_hash_table_iter_init(&iterator, options->table);
171167
gpointer _key, _value;
@@ -179,15 +175,15 @@ void _Window::parse_commands(Command cmd)
179175
}
180176
}
181177

182-
void _Window::init_backend()
178+
void QCPDialog::init_backend()
183179
{
184180
event_callback add_cb = (event_callback)add_printer_callback;
185181
event_callback rem_cb = (event_callback)remove_printer_callback;
186182
f = get_new_FrontendObj(NULL, add_cb, rem_cb);
187183
connect_to_dbus(f);
188184
}
189185

190-
void _Window::clearPrinters()
186+
void QCPDialog::clearPrinters()
191187
{
192188
QObject *obj = root->rootObject->findChild<QObject *>("generalObject");
193189
if (obj) {
@@ -197,21 +193,18 @@ void _Window::clearPrinters()
197193
qDebug() << "generalObject Not Found";
198194
}
199195

200-
void _Window::newPrinterSelected(const QString &printer)
196+
void QCPDialog::newPrinterSelected(const QString &printer)
201197
{
202-
Command cmd;
203-
cmd.command = "get-all-options";
204-
cmd.arg1 = printer.toStdString();
205-
if (cmd.arg1.compare("") != 0)
206-
parse_commands(cmd);
198+
Options *options = get_all_printer_options(f, printer.toLatin1().data(), "CUPS");
199+
qDebug() << "Total Options:" << options->count;
207200
}
208201

209-
void _Window::remotePrintersToggled(const QString &enabled)
202+
void QCPDialog::remotePrintersToggled(const QString &enabled)
210203
{
211204
bool toggle = enabled.compare("true") == 0 ? true : false;
212205
Command cmd;
213206
cmd.command = toggle ? "unhide-remote-cups" : "hide-remote-cups";
214-
parse_commands(cmd);
207+
parse_commands(&cmd);
215208
}
216209

217210
void ui_add_job_hold_until(char *startJobOption) {}
Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,31 @@
1-
#ifndef WINDOW_H
2-
#define WINDOW_H
1+
#ifndef QCPDIALOG_H
2+
#define QCPDIALOG_H
33

4-
#include <QGridLayout>
5-
#include <QPainter>
64
#include <QAbstractPrintDialog>
7-
#include <QPrinter>
8-
#include "components.h"
95

10-
#include <QDebug>
6+
class QPrinter;
7+
class QGridLayout;
8+
class Tabs;
9+
class Root;
10+
class Preview;
11+
class Controls;
1112

12-
extern "C" {
13-
#include <CPD.h>
14-
}
13+
struct _FrontendObj;
14+
using FrontendObj = _FrontendObj;
1515

16-
class QPrinter;
16+
struct _GMainLoop;
17+
using GMainLoop = _GMainLoop;
1718

18-
static void add_printer_callback(PrinterObj *p);
19-
static void remove_printer_callback(char *printer_name);
20-
void ui_add_printer_aux(gpointer key, gpointer value, gpointer user_data);
19+
struct _PrinterObj;
20+
using PrinterObj = _PrinterObj;
2121

22-
typedef struct {
23-
std::string command;
24-
std::string arg1;
25-
std::string arg2;
26-
} Command;
22+
using gpointer = void *;
2723

28-
class _Window : public QWidget
24+
class QCPDialog : public QAbstractPrintDialog
2925
{
3026
Q_OBJECT
3127
public:
32-
FrontendObj *f;
33-
Tabs *tabs;
34-
Root *root;
35-
Preview *preview;
36-
Controls *controls;
37-
QGridLayout *masterLayout;
38-
39-
_Window(QPrinter *printer, QWidget *parent = Q_NULLPTR);
28+
QCPDialog(QPrinter *printer, QWidget *parent = Q_NULLPTR);
4029
void init_backend();
4130
void addPrinter(const char *printer);
4231
void clearPrinters();
@@ -46,8 +35,11 @@ class _Window : public QWidget
4635
void addJobHoldUntil(char *startJobOption) {}
4736
void addPagesPerSize(char *pages) {}
4837
void updateAllOptions(const QString &printer);
49-
void parse_commands(Command cmd);
50-
gpointer ui_add_printer(gpointer user_data);
38+
void parse_commands(gpointer user_data);
39+
int exec() override
40+
{
41+
return QDialog::exec();
42+
}
5143

5244
public Q_SLOTS:
5345
void tabBarIndexChanged(qint32 index);
@@ -56,13 +48,23 @@ public Q_SLOTS:
5648
void newPrinterSelected(const QString &printer);
5749
void remotePrintersToggled(const QString &enabled);
5850

51+
private:
52+
FrontendObj *f;
53+
Tabs *tabs;
54+
Root *root;
55+
Preview *preview;
56+
Controls *controls;
57+
QGridLayout *masterLayout;
5958
};
6059

6160
class Q_PRINTSUPPORT_EXPORT CPrintDialog : public QAbstractPrintDialog
6261
{
6362
public:
6463
CPrintDialog(QPrinter *printer, QWidget *parent = Q_NULLPTR);
65-
int exec() override {}
64+
int exec() override
65+
{
66+
return 0;
67+
}
6668
};
6769

68-
#endif // WINDOW_H
70+
#endif // QCPDIALOG_H

common-print-dialog.pro

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,24 @@ unix {
1414
}
1515

1616
SOURCES += \
17-
cpd.cpp \
1817
app/components.cpp \
19-
app/window.cpp
18+
app/QCPDialog.cpp \
19+
cpd.cpp
2020

21-
RESOURCES += qml.qrc
21+
HEADERS += \
22+
app/components.h \
23+
app/QCPDialog.h \
24+
cpd.h \
25+
cpd_global.h
2226

23-
LIBS += -lcups
2427

25-
DEPENDPATH += backends/cups
28+
LIBS += -L/usr/lib/ -lCPDFrontend -lcups
29+
30+
DEPENDPATH += $$PWD/backends/cups/release/headers
2631
INCLUDEPATH += $${DEPENDPATH}
2732

33+
RESOURCES += qml.qrc
34+
2835
# Additional import path used to resolve QML modules in Qt Creator's code model
2936
QML_IMPORT_PATH =
3037

@@ -46,14 +53,3 @@ DEFINES += QT_DEPRECATED_WARNINGS COMMONPRINTDIALOGLIBRARY_LIBRARY
4653
qnx: target.path = /tmp/$${TARGET}/bin
4754
else: unix:!android: target.path = /opt/$${TARGET}/bin
4855
!isEmpty(target.path): INSTALLS += target
49-
50-
HEADERS += \
51-
cpd.h \
52-
cpd_global.h \
53-
app/components.h \
54-
app/window.h
55-
56-
LIBS += -L/usr/lib/ -lCPDFrontend
57-
58-
INCLUDEPATH += $$PWD/backends/cups/release/headers
59-
DEPENDPATH += $$PWD/backends/cups/release/headers

cpd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "cpd.h"
2-
#include "app/window.h"
2+
#include "app/QCPDialog.h"
33

44
CPD::CPD(QPrinter *printer, QWidget *parent) :
55
QWidget(parent)

0 commit comments

Comments
 (0)