Index: qr_codes.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/qr_codes/Attic/qr_codes.admin.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 qr_codes.admin.inc
--- qr_codes.admin.inc	28 Jun 2010 17:09:33 -0000	1.1.2.1
+++ qr_codes.admin.inc	30 Jun 2010 06:46:12 -0000
@@ -9,13 +9,53 @@ function qr_codes_settings() {
   $options = module_invoke_all('qr_codes', 'list');
 
   if (count($options)) {
+    $engine = variable_get('qr_codes_engine', 'qr_codes_google_chart:google_chart');
+
+    $form['#submit'][] = '_qr_codes_submit';
+
+    // Send also the old engine to test if will change.
+    $form['qr_codes_engine_old'] = array(
+      '#type' => 'value',
+      '#value' => $engine,
+    );
+
     $form['qr_codes_engine'] = array(
       '#type' => 'select',
       '#title' => t('Select the QR encoding engine'),
       '#description' => '<p>'. t('Select which engine/API is used to generate QR Code images. The following options are available as enabled modules:') .'</p>'. theme('item_list', module_invoke_all('qr_codes', 'description')) .'<p>'. t('If your option is not in the list, you should enable the appropriate sub-module. Additionaly you can plug other engines/APIs by implementing <code>hook_qr_codes()</code> in your module.') .'</p>',
       '#options' => $options,
-      '#default_value' => variable_get('qr_codes_engine', 'qr_codes_google_chart:google_chart'),
+      '#default_value' => $engine,
+    );
+
+    $count = count(file_scan_directory(file_directory_path() .'/qr_codes', '\.png$'));
+    $form['qr_codes_clear_cache'] = array(
+      '#type' => 'fieldset',
+      '#title' => $count ? t('Cache: @count files cached', array('@count' => $count)) : t('Cache: There are no files in cache'),
+      '#collapsible' => FALSE,
+      '#collapsed' => FALSE,
+      '#description' => t('Once a QR Codes image is created, it\'s saved locally. Next time when the same QR Code is requested it will be served from the local directory. This will increase the performance. You can configure a cache lifetime or manually clear the cache by pressing button bellow.'),
     );
+
+    $form['qr_codes_clear_cache']['qr_codes_cache_lifetime'] = array(
+      '#type' => 'select',
+      '#title' => t('Cache lifetime'),
+      '#description' => t('You can configure how long locally files will remain in cache.'),
+      '#options' => array(
+        0 => t('Forever'),
+        1 => t('One day'),
+        10 => t('10 days'),
+        50 => t('50 days'),
+        100 => t('100 days'),
+        150 => t('150 days'),
+      ),
+      '#default_value' => variable_get('qr_codes_cache_lifetime', 0),
+    );
+    $form['qr_codes_clear_cache']['clear'] = array(
+      '#type' => 'submit',
+      '#value' => t('Clear cache now!'),
+      '#submit' => array('_qr_codes_clear_cache'),
+    );
+
     return system_settings_form($form);
   }
   else {
@@ -43,3 +83,22 @@ function qr_codes_settings() {
 function qr_codes_engine_settings($form_state, $module, $engine_id) {
   return system_settings_form(module_invoke($module, 'qr_codes', 'config', $engine_id));
 }
+
+/**
+ * Clear local files cache.
+ */
+function _qr_codes_clear_cache() {
+  $count = count(file_scan_directory(file_directory_path() .'/qr_codes', '\.png$', array('.', '..', 'CVS', '.svn'), 'file_delete'));
+  if ($count) {
+    drupal_set_message(t('QR Codes local cache cleared. @count files were deleted.', array('@count' => $count)));
+  }
+}
+
+/**
+ * Implement an additional submit callback to the settings form.
+ */
+function _qr_codes_submit($form, $form_state) {
+  if ($form_state['values']['qr_codes_engine_old'] != $form_state['values']['qr_codes_engine']) {
+    _qr_codes_clear_cache();
+  }
+}
Index: qr_codes.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/qr_codes/qr_codes.module,v
retrieving revision 1.2.2.2
diff -u -p -r1.2.2.2 qr_codes.module
--- qr_codes.module	28 Jun 2010 17:09:33 -0000	1.2.2.2
+++ qr_codes.module	30 Jun 2010 06:46:12 -0000
@@ -60,6 +60,23 @@ function qr_codes_menu() {
 }
 
 /**
+ * Implementation of hook_cron().
+ *
+ * @see: http://api.drupal.org/api/function/hook_cron/6
+ */
+function qr_codes_cron() {
+  if (variable_get('qr_codes_cache_lifetime', 0)) {
+    $now = time();
+    $life = variable_get('qr_codes_cache_lifetime', 0) * 24 * 60 * 60;
+    foreach (file_scan_directory(file_directory_path() .'/qr_codes', '\.png$') as $file) {
+      if ($now - filemtime($file->filename) > $life) {
+        file_delete($file->filename);
+      }
+    }
+  }
+}
+
+/**
  * Returns the file path of a qr code image
  *
  * @param string $data
