|
1 | 1 | #include "window.h" |
| 2 | +#include <QDebug> |
2 | 3 |
|
3 | | -Window::Window() : |
| 4 | +_Window *_window; |
| 5 | + |
| 6 | +_Window::_Window(QWidget *parent) : |
| 7 | + QWidget(parent), |
| 8 | + masterLayout(new QGridLayout(this)), |
4 | 9 | tabs(new Tabs(this)), |
5 | | - content(new QHBoxLayout()), |
6 | 10 | root(new Root(this)), |
7 | 11 | preview(new Preview(this)), |
8 | | - controls(new Controls(this)), |
9 | | - container(new QVBoxLayout()) |
| 12 | + controls(new Controls(this)) |
10 | 13 | { |
11 | 14 | /* |
12 | | - * container |
| 15 | + * masterLayout |
13 | 16 | * |-tabs |
14 | | - * |-content |
15 | | - * |-root |
16 | | - * |-preview |
| 17 | + * |-root -- preview |
17 | 18 | * |-controls |
18 | 19 | */ |
19 | | - setCentralWidget(new QWidget(this)); |
20 | | - |
21 | | - tabs->setMinimumSize(700, 32); |
22 | 20 | QObject::connect(tabs->rootObject, |
23 | 21 | SIGNAL(tabBarIndexChanged(qint32)), |
24 | 22 | this, |
@@ -49,51 +47,144 @@ Window::Window() : |
49 | 47 | preview, |
50 | 48 | SLOT(showPrevPage())); |
51 | 49 |
|
52 | | - content->setSpacing(0); |
53 | | - content->setMargin(0); |
| 50 | + tabs->setMinimumSize(700, 32); |
54 | 51 |
|
55 | 52 | root->setMinimumSize(320, 408); |
56 | 53 |
|
57 | 54 | preview->setMinimumSize(380, 408); |
58 | 55 |
|
59 | | - content->addWidget(root); |
60 | | - content->addWidget(preview); |
61 | | - |
62 | 56 | controls->setMinimumSize(700, 40); |
63 | 57 |
|
64 | | - container->setSpacing(0); |
65 | | - container->setMargin(0); |
66 | | - container->addWidget(tabs); |
67 | | - container->addLayout(content); |
68 | | - container->addWidget(controls); |
| 58 | + masterLayout->setColumnMinimumWidth(0, 320); |
| 59 | + masterLayout->setColumnMinimumWidth(1, 380); |
| 60 | + masterLayout->setRowMinimumHeight(0, 32); |
| 61 | + masterLayout->setRowMinimumHeight(1, 408); |
| 62 | + masterLayout->setRowMinimumHeight(2, 40); |
| 63 | + masterLayout->setSpacing(0); |
| 64 | + masterLayout->setMargin(0); |
| 65 | + |
| 66 | + masterLayout->addWidget(tabs, 0, 0, 1, 2); |
| 67 | + masterLayout->addWidget(root, 1, 0, 1, 1); |
| 68 | + masterLayout->addWidget(preview, 1, 1, 1, 1); |
| 69 | + masterLayout->addWidget(controls, 2, 0, 1, 2); |
69 | 70 |
|
70 | | - preview->widgetHeight = content->itemAt(1)->geometry().height(); |
| 71 | + preview->widgetHeight = masterLayout->itemAt(2)->geometry().height(); |
71 | 72 |
|
72 | | - centralWidget()->setLayout(container); |
73 | 73 | adjustSize(); |
| 74 | + |
| 75 | + setMaximumSize(700, 480); |
| 76 | + setMinimumSize(700, 480); |
| 77 | + |
| 78 | + init_backend(); |
| 79 | +} |
| 80 | + |
| 81 | +Window::Window(QWidget *parent) : |
| 82 | + QWidget(parent) |
| 83 | +{ |
| 84 | + _window = new _Window(parent); |
| 85 | + _window->show(); |
74 | 86 | } |
75 | 87 |
|
76 | 88 | void Window::resizeEvent(QResizeEvent *event) { |
77 | | - QMainWindow::resizeEvent(event); |
78 | | - tabs->resize(container->itemAt(0)->geometry()); |
79 | | - root->resize(content->itemAt(0)->geometry()); |
80 | | - controls->resize(container->itemAt(2)->geometry()); |
81 | | - preview->widgetHeight = content->itemAt(1)->geometry().height(); |
82 | | - preview->setZoom(preview->currentZoomFactor); |
| 89 | + QWidget::resizeEvent(event); |
| 90 | +// _window->tabs->resize(_window->container->itemAt(0)->geometry()); |
| 91 | +// _window->root->resize(_window->content->itemAt(0)->geometry()); |
| 92 | +// _window->controls->resize(_window->container->itemAt(2)->geometry()); |
| 93 | +// _window->preview->widgetHeight = _window->content->itemAt(1)->geometry().height(); |
| 94 | +// _window->preview->setZoom(_window->preview->currentZoomFactor); |
83 | 95 | } |
84 | 96 |
|
85 | | -void Window::tabBarIndexChanged(qint32 index) { |
| 97 | +void _Window::tabBarIndexChanged(qint32 index) { |
86 | 98 | root->rootObject->setProperty("index", index); |
87 | 99 | } |
88 | 100 |
|
89 | | -void Window::swipeViewIndexChanged(qint32 index) { |
| 101 | +void _Window::swipeViewIndexChanged(qint32 index) { |
90 | 102 | tabs->rootObject->setProperty("index", index); |
91 | 103 | } |
92 | 104 |
|
93 | | -void Window::cancelButtonClicked() { |
| 105 | +void _Window::cancelButtonClicked() { |
94 | 106 | exit(0); |
95 | 107 | } |
96 | 108 |
|
| 109 | +static int add_printer_callback(PrinterObj *p) { |
| 110 | + printf("print_frontend.c : Printer %s added!\n", p->name); |
| 111 | +} |
| 112 | + |
| 113 | +static int remove_printer_callback(char *printer_name) { |
| 114 | + printf("print_frontend.c : Printer %s removed!\n", printer_name); |
| 115 | +} |
| 116 | + |
| 117 | +gpointer _Window::ui_add_printer(gpointer user_data) { |
| 118 | + /* |
| 119 | + * Need this delay so that the FrontendObj |
| 120 | + * initialization completes |
| 121 | + */ |
| 122 | + bool* enabled = (bool*)user_data; |
| 123 | + for (int i = 0; i < 100000000; i++); |
| 124 | + Command cmd; |
| 125 | + if (*enabled) { |
| 126 | + cmd.command = "unhide-remote-cups"; |
| 127 | + parse_commands(&cmd); |
| 128 | + } |
| 129 | + else { |
| 130 | + cmd.command = "hide-remote-cups"; |
| 131 | + parse_commands(&cmd); |
| 132 | + } |
| 133 | + clearPrinters(); |
| 134 | + g_hash_table_foreach(f->printer, ui_add_printer_aux, NULL); |
| 135 | +} |
| 136 | + |
| 137 | +void ui_add_printer_aux(gpointer key, gpointer value, gpointer user_data) { |
| 138 | + _window->addPrinter((const char*)key); |
| 139 | + qDebug() << "Added" << (const char*)key; |
| 140 | +} |
| 141 | + |
| 142 | +void _Window::addPrinter(const char *printer) { |
| 143 | + QObject* obj = root->rootObject->findChild<QObject*>("generalObject"); |
| 144 | + if (obj) { |
| 145 | + QMetaObject::invokeMethod(obj, |
| 146 | + "updateDestinationModel", |
| 147 | + Q_ARG(QVariant, printer)); |
| 148 | + } |
| 149 | + else |
| 150 | + qDebug() << "generalObject Not Found"; |
| 151 | +} |
| 152 | + |
| 153 | +gpointer _Window::parse_commands(gpointer user_data) { |
| 154 | + Command* cmd = (Command*)user_data; |
| 155 | + if (cmd->command.compare("hide-remote-cups") == 0) |
| 156 | + hide_remote_cups_printers(f); |
| 157 | + else if (cmd->command.compare("unhide-remote-cups") == 0) |
| 158 | + unhide_remote_cups_printers(f); |
| 159 | + else if (cmd->command.compare("get-all-options") == 0) { |
| 160 | + char printerName[300]; |
| 161 | + strcpy(printerName, cmd->arg1.c_str()); |
| 162 | + get_all_printer_options(_window->f, printerName); |
| 163 | + } |
| 164 | +} |
| 165 | + |
| 166 | +void _Window::init_backend() { |
| 167 | + event_callback add_cb = (event_callback)add_printer_callback; |
| 168 | + event_callback rem_cb = (event_callback)remove_printer_callback; |
| 169 | + f = get_new_FrontendObj(NULL, add_cb, rem_cb); |
| 170 | + bool enabled = true; |
| 171 | + //g_thread_new("add_printer_thread", (GThreadFunc)ui_add_printer, &enabled); |
| 172 | + ui_add_printer(&enabled); |
| 173 | + connect_to_dbus(f); |
| 174 | + loop = g_main_loop_new(NULL, FALSE); |
| 175 | + //g_main_loop_run(loop); |
| 176 | +} |
| 177 | + |
| 178 | +void _Window::clearPrinters() { |
| 179 | +// QObject* obj = root->rootObject->findChild<QObject*>("generalObject"); |
| 180 | +// if (obj) { |
| 181 | +// QMetaObject::invokeMethod(obj, |
| 182 | +// "clearDestinationModel"); |
| 183 | +// } |
| 184 | +// else |
| 185 | +// qDebug() << "generalObject Not Found"; |
| 186 | +} |
| 187 | + |
97 | 188 | Tabs::Tabs(QWidget* parent) : |
98 | 189 | QWidget(parent), |
99 | 190 | tabs(new QQuickWidget(QUrl("qrc:/app/Tabs.qml"), this)) { |
@@ -201,3 +292,13 @@ void Controls::resize(const QRect& rect) { |
201 | 292 | QWidget::resize(rect.width(), rect.height()); |
202 | 293 | controls->resize(rect.width(), rect.height()); |
203 | 294 | } |
| 295 | + |
| 296 | +void ui_add_job_hold_until(char *startJobOption) {} |
| 297 | + |
| 298 | +void ui_add_maximum_print_copies(char *_copies) {} |
| 299 | + |
| 300 | +void ui_add_pages_per_side(char *pages) {} |
| 301 | + |
| 302 | +void ui_clear_supported_media() {} |
| 303 | + |
| 304 | +void ui_add_supported_media(char *media) {} |
0 commit comments