7 #include "wvcupsmanager.h"
9 #include "wvprintconfwatcher.h"
11 #include "wvprintuniconfkeys.h"
15 WvPrintConfWatcher::WvPrintConfWatcher(WvLog
&_log
, const UniConf
&_cfg
)
16 : log(_log
), cfg(_cfg
), queues(16), cups(NULL
)
18 /* needed for editing of the 'WvPrint/aliases' on the commandline */
19 watches
.add(cfg
[WVPRINT_ALIASES_KEYS
],
20 UniConfCallback(this, &WvPrintConfWatcher::addalias_callback
), true);
22 /* handle all the queues thru UniCallbacks */
23 watches
.add(cfg
[WVPRINT_QUEUES_KEYS
],
24 UniConfCallback(this, &WvPrintConfWatcher::addqueue_callback
), true);
28 void WvPrintConfWatcher::addalias_callback(const UniConf
&_cfg
, const UniConfKey
&_key
)
30 /* if the user has invoked this callback .. not when we're doing a config
31 * aliases. Also, don't let them delete the lp alias */
32 // if (!need_alias_config)
35 WvString queuename
= _cfg
[_key
].getme("");
36 if (!!queuename
&& queues
[queuename
])
38 //configure_aliases();
47 void WvPrintConfWatcher::addqueue_callback(const UniConf
&_cfg
, const UniConfKey
&_key
)
49 log(WvLog::Debug1
, "addqueue_callback. Key = %s\n", _key
);
51 if (!!_key
.printable())
54 subkeys
.split(_key
, "/");
55 if (subkeys
.count() == 1)
57 _add_queue(*subkeys
.first());
61 _update_queue(*subkeys
.first());
67 void WvPrintConfWatcher::init_config()
69 log(WvLog::Debug1
, "init_config()\n");
72 log(WvLog::Warning
, "queues is not empty. Emptying\n");
76 UniConf::Iter
cfgit(cfg
[WVPRINT_QUEUES_KEYS
]);
78 /* Iterate over all queues .. starts only the real ones */
79 for (cfgit
.rewind(); cfgit
.next(); )
81 WvString
queuename(cfgit().key().printable());
82 log(WvLog::Debug1
, "adding a queue\n");
83 _add_queue(queuename
);
87 WvString
WvPrintConfWatcher::get_printer_state(WvStringParm queuename
)
90 PrintQueueName
*qn
= queues
[queuename
];
93 state
= qn
->queue
->get_state();
99 int WvPrintConfWatcher::count_jobs(WvStringParm queuename
)
102 PrintQueueName
*qn
= queues
[queuename
];
105 count
= qn
->queue
->job_count();
111 bool WvPrintConfWatcher::job_exists(WvStringParm queuename
, int job_num
)
114 PrintQueueName
*qn
= queues
[queuename
];
117 found
= qn
->queue
->job_exists(queuename
, job_num
);
123 bool WvPrintConfWatcher::cancel_job(WvStringParm queuename
, int job_num
)
125 PrintQueueName
*qn
= queues
[queuename
];
128 return qn
->queue
->cancel(job_num
);
135 void WvPrintConfWatcher::_add_queue(WvStringParm name
)
137 PrintQueue
*queue
= PrintQueue::new_queue(name
, cfg
, log
);
141 queue
->set_cups_manager(cups
);
142 queues
.add(new PrintQueueName(queue
->name
, queue
), true);
143 log(WvLog::Debug
, "Added new queue %s.\n", name
);
148 log(WvLog::Error
, "Could not add new queue %s; disabling.\n", name
);
153 void WvPrintConfWatcher::_update_queue(WvStringParm queuename
)
155 PrintQueue
*queue
= queues
[queuename
]->queue
;
157 // FIXME: looks like this can happen to often. Perhaps should we add the queue
158 // to a list and reconfig every once and while
166 void WvPrintConfWatcher::_remove_queue(WvStringParm queuename
)
168 /* Clean up both queue and uniconf */
169 PrintQueueName
*q
= queues
[queuename
];
173 log(WvLog::Debug
, "Removing queue %s\n", queuename
);
178 log(WvLog::Debug
, "Could not find queue %s\n", queuename
);