@@ -160,7 +160,7 @@ static void on_printer_state_changed(GDBusConnection *connection,
160
160
f -> printer_cb (f , p , CPDB_CHANGE_PRINTER_STATE_CHANGED );
161
161
}
162
162
163
- static GDBusConnection * get_dbus_connection ()
163
+ GDBusConnection * cpdbGetDbusConnection ()
164
164
{
165
165
gchar * bus_addr ;
166
166
GError * error = NULL ;
@@ -190,7 +190,7 @@ void cpdbConnectToDBus(cpdb_frontend_obj_t *f)
190
190
GMainContext * context ;
191
191
GError * error = NULL ;
192
192
193
- if ((f -> connection = get_dbus_connection ()) == NULL )
193
+ if ((f -> connection = cpdbGetDbusConnection ()) == NULL )
194
194
{
195
195
loginfo ("Couldn't connect to DBus\n" );
196
196
return ;
@@ -291,6 +291,69 @@ static void fetchPrinterListFromBackend(cpdb_frontend_obj_t *f, const char *back
291
291
}
292
292
}
293
293
294
+ bool cpdbRefreshPrinterList (cpdb_frontend_obj_t * f , char * backend )
295
+ {
296
+ int num_printers ;
297
+ GVariantIter iter ;
298
+ GVariant * printers , * printer ;
299
+ PrintBackend * proxy ;
300
+ GError * error = NULL ;
301
+ cpdb_printer_obj_t * p ;
302
+
303
+ if ((proxy = g_hash_table_lookup (f -> backend , backend )) == NULL )
304
+ {
305
+ logerror ("Couldn't get %s proxy object\n" , backend );
306
+ return false;
307
+ }
308
+ print_backend_call_get_all_printers_sync (proxy , & num_printers ,
309
+ & printers , NULL , & error );
310
+ if (error )
311
+ {
312
+ logerror ("Error getting %s printer list : %s\n" , backend , error -> message );
313
+ return false;
314
+ }
315
+ logdebug ("Fetched %d printers from backend %s\n" , num_printers , backend );
316
+ g_variant_iter_init (& iter , printers );
317
+ while (g_variant_iter_loop (& iter , "(v)" , & printer ))
318
+ {
319
+ p = cpdbGetNewPrinterObj ();
320
+ cpdbFillBasicOptions (p , printer );
321
+ if (f -> last_saved_settings != NULL )
322
+ cpdbCopySettings (f -> last_saved_settings , p -> settings );
323
+ cpdbAddPrinter (f , p );
324
+ }
325
+
326
+ GHashTableIter iterator ;
327
+ gpointer key , value ;
328
+
329
+ g_hash_table_iter_init (& iterator , f -> printer );
330
+
331
+ while (g_hash_table_iter_next (& iterator , & key , & value )) {
332
+ cpdb_printer_obj_t * printer_obj = (cpdb_printer_obj_t * )value ;
333
+ char * backend_name = printer_obj -> backend_name ;
334
+
335
+ // Compare the backend_name with the provided one
336
+ if (strcmp (backend_name , backend ) == 0 ) {
337
+ // Check if backend_name is not in the printers hashtable
338
+ char * printer_name = cpdbConcatSep (printer_obj -> id , backend_name );
339
+ g_variant_iter_init (& iter , printers );
340
+ int printer_exists = 0 ;
341
+ while (g_variant_iter_loop (& iter , "(v)" , & printer ))
342
+ {
343
+ cpdb_printer_obj_t * temp = cpdbGetNewPrinterObj ();
344
+ cpdbFillBasicOptions (temp , printer );
345
+ if (strcmp (temp -> name , printer_obj -> name ) == 0 ){
346
+ printer_exists = 1 ;
347
+ break ;
348
+ }
349
+ cpdbDeletePrinterObj (temp );
350
+ }
351
+ if (printer_exists == 0 ) cpdbRemovePrinter (f , printer_obj -> id , backend_name );
352
+ }
353
+ }
354
+ return true;
355
+ }
356
+
294
357
// Helper function to add existing backends to a hash table
295
358
static void add_to_hash_table (gpointer key , gpointer value , gpointer user_data ) {
296
359
GHashTable * hash_table = (GHashTable * )user_data ;
@@ -1307,7 +1370,7 @@ cpdb_printer_obj_t *cpdbResurrectPrinterFromFile(const char *filename)
1307
1370
p -> backend_name = cpdbGetStringCopy (strtok (buf , "#" ));
1308
1371
1309
1372
service_name = cpdbConcat (CPDB_BACKEND_PREFIX , p -> backend_name );
1310
- if ((connection = get_dbus_connection ()) == NULL )
1373
+ if ((connection = cpdbGetDbusConnection ()) == NULL )
1311
1374
{
1312
1375
logerror ("Error resurrecting printer : Couldn't get dbus connection\n" );
1313
1376
goto failed ;
0 commit comments