keepyourhead 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/COPYING.txt +674 -0
  2. data/LICENSE.rdoc +20 -0
  3. data/README.rdoc +3 -0
  4. data/bin/keepyourhead +6 -0
  5. data/data/glade/DialogEditLatex.glade +180 -0
  6. data/data/glade/DialogEditText.glade +66 -0
  7. data/data/glade/DialogTrainStart.glade +101 -0
  8. data/data/glade/WindowEdit.glade +1419 -0
  9. data/data/glade/WindowTrain.glade +271 -0
  10. data/data/images/error_back.png +0 -0
  11. data/data/images/error_front.png +0 -0
  12. data/data/images/loading_back.png +0 -0
  13. data/data/images/loading_front.png +0 -0
  14. data/lib/Keepyourhead.rb +62 -0
  15. data/lib/Keepyourhead/Application.rb +94 -0
  16. data/lib/Keepyourhead/Cache.rb +233 -0
  17. data/lib/Keepyourhead/Compilation.rb +38 -0
  18. data/lib/Keepyourhead/Images.rb +62 -0
  19. data/lib/Keepyourhead/Preferences.rb +52 -0
  20. data/lib/Keepyourhead/Requirements.rb +72 -0
  21. data/lib/Keepyourhead/Resources.rb +45 -0
  22. data/lib/Keepyourhead/Training.rb +132 -0
  23. data/lib/Keepyourhead/Utils.rb +97 -0
  24. data/lib/Keepyourhead/Version.rb +43 -0
  25. data/lib/Keepyourhead/database/Base.rb +77 -0
  26. data/lib/Keepyourhead/database/BaseStatistic.rb +63 -0
  27. data/lib/Keepyourhead/database/BaseTopicFlashcardContainer.rb +43 -0
  28. data/lib/Keepyourhead/database/Collection.rb +43 -0
  29. data/lib/Keepyourhead/database/Database.rb +139 -0
  30. data/lib/Keepyourhead/database/File.rb +224 -0
  31. data/lib/Keepyourhead/database/FileRoot.rb +44 -0
  32. data/lib/Keepyourhead/database/Flashcard.rb +116 -0
  33. data/lib/Keepyourhead/database/Topic.rb +40 -0
  34. data/lib/Keepyourhead/database/Visitor.rb +33 -0
  35. data/lib/Keepyourhead/database/XmlAccessor.rb +315 -0
  36. data/lib/Keepyourhead/gui/Action.rb +91 -0
  37. data/lib/Keepyourhead/gui/DialogEditLatex.rb +132 -0
  38. data/lib/Keepyourhead/gui/DialogEditText.rb +104 -0
  39. data/lib/Keepyourhead/gui/DialogTrainStart.rb +63 -0
  40. data/lib/Keepyourhead/gui/FlashcardViewController.rb +112 -0
  41. data/lib/Keepyourhead/gui/WindowEdit.rb +469 -0
  42. data/lib/Keepyourhead/gui/WindowEditActions.rb +440 -0
  43. data/lib/Keepyourhead/gui/WindowEditAdapters.rb +329 -0
  44. data/lib/Keepyourhead/gui/WindowTrain.rb +167 -0
  45. data/lib/Keepyourhead/style/Style.rb +48 -0
  46. data/lib/Keepyourhead/style/StyleLatex.rb +235 -0
  47. metadata +100 -0
@@ -0,0 +1,271 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
3
+ <!--Generated with glade3 3.4.5 on Sun Sep 28 21:13:34 2008 -->
4
+ <glade-interface>
5
+ <widget class="GtkWindow" id="window_train">
6
+ <property name="title" translatable="yes">KeepYourHead - Training</property>
7
+ <signal name="destroy" handler="onDestroy"/>
8
+ <child>
9
+ <widget class="GtkVBox" id="vbox2">
10
+ <property name="visible">True</property>
11
+ <child>
12
+ <widget class="GtkAlignment" id="alignment2">
13
+ <property name="visible">True</property>
14
+ <property name="xscale">0.40000000596046448</property>
15
+ <property name="yscale">0.40000000596046448</property>
16
+ <child>
17
+ <widget class="GtkProgressBar" id="progressbarFlashcards">
18
+ <property name="visible">True</property>
19
+ <property name="text" translatable="yes"></property>
20
+ </widget>
21
+ </child>
22
+ </widget>
23
+ </child>
24
+ <child>
25
+ <widget class="GtkAlignment" id="alignment6">
26
+ <property name="visible">True</property>
27
+ <property name="xscale">0.40000000596046448</property>
28
+ <property name="yscale">0.40000000596046448</property>
29
+ <child>
30
+ <widget class="GtkProgressBar" id="progressbarTime">
31
+ <property name="visible">True</property>
32
+ <property name="text" translatable="yes"></property>
33
+ </widget>
34
+ </child>
35
+ </widget>
36
+ <packing>
37
+ <property name="position">1</property>
38
+ </packing>
39
+ </child>
40
+ <child>
41
+ <widget class="GtkAlignment" id="alignment1">
42
+ <property name="visible">True</property>
43
+ <property name="top_padding">50</property>
44
+ <property name="bottom_padding">50</property>
45
+ <property name="left_padding">80</property>
46
+ <property name="right_padding">80</property>
47
+ <child>
48
+ <widget class="GtkScrolledWindow" id="scrolledwindowNotebook">
49
+ <property name="width_request">650</property>
50
+ <property name="height_request">650</property>
51
+ <property name="visible">True</property>
52
+ <property name="can_focus">True</property>
53
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
54
+ <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
55
+ <child>
56
+ <widget class="GtkViewport" id="viewport1">
57
+ <property name="visible">True</property>
58
+ <property name="resize_mode">GTK_RESIZE_QUEUE</property>
59
+ <child>
60
+ <widget class="GtkNotebook" id="notebook">
61
+ <property name="visible">True</property>
62
+ <property name="can_focus">True</property>
63
+ <property name="show_tabs">False</property>
64
+ <child>
65
+ <widget class="GtkVBox" id="vbox1">
66
+ <property name="visible">True</property>
67
+ <child>
68
+ <widget class="GtkImage" id="imageFront">
69
+ <property name="visible">True</property>
70
+ <property name="stock">gtk-missing-image</property>
71
+ </widget>
72
+ </child>
73
+ <child>
74
+ <widget class="GtkAlignment" id="alignment4">
75
+ <property name="visible">True</property>
76
+ <property name="xscale">0.5</property>
77
+ <child>
78
+ <widget class="GtkHBox" id="hboxFront">
79
+ <property name="visible">True</property>
80
+ <child>
81
+ <widget class="GtkLabel" id="label3">
82
+ <property name="visible">True</property>
83
+ <property name="label" translatable="yes">Seite</property>
84
+ </widget>
85
+ </child>
86
+ <child>
87
+ <widget class="GtkHScale" id="hscaleFront">
88
+ <property name="visible">True</property>
89
+ <property name="can_focus">True</property>
90
+ <property name="adjustment">0 0 100 1 10 10</property>
91
+ <property name="draw_value">False</property>
92
+ </widget>
93
+ <packing>
94
+ <property name="position">1</property>
95
+ </packing>
96
+ </child>
97
+ </widget>
98
+ </child>
99
+ </widget>
100
+ <packing>
101
+ <property name="expand">False</property>
102
+ <property name="position">1</property>
103
+ </packing>
104
+ </child>
105
+ </widget>
106
+ </child>
107
+ <child>
108
+ <widget class="GtkLabel" id="label1">
109
+ <property name="visible">True</property>
110
+ <property name="label" translatable="yes">page 1</property>
111
+ </widget>
112
+ <packing>
113
+ <property name="type">tab</property>
114
+ <property name="tab_fill">False</property>
115
+ </packing>
116
+ </child>
117
+ <child>
118
+ <widget class="GtkVBox" id="vbox3">
119
+ <property name="visible">True</property>
120
+ <child>
121
+ <widget class="GtkImage" id="imageBack">
122
+ <property name="visible">True</property>
123
+ <property name="stock">gtk-missing-image</property>
124
+ </widget>
125
+ </child>
126
+ <child>
127
+ <widget class="GtkAlignment" id="alignment5">
128
+ <property name="visible">True</property>
129
+ <property name="xscale">0.5</property>
130
+ <child>
131
+ <widget class="GtkHBox" id="hboxBack">
132
+ <property name="visible">True</property>
133
+ <child>
134
+ <widget class="GtkLabel" id="label4">
135
+ <property name="visible">True</property>
136
+ <property name="label" translatable="yes">Seite</property>
137
+ </widget>
138
+ </child>
139
+ <child>
140
+ <widget class="GtkHScale" id="hscaleBack">
141
+ <property name="visible">True</property>
142
+ <property name="can_focus">True</property>
143
+ <property name="adjustment">0 0 100 1 10 10</property>
144
+ <property name="draw_value">False</property>
145
+ </widget>
146
+ <packing>
147
+ <property name="position">1</property>
148
+ </packing>
149
+ </child>
150
+ </widget>
151
+ </child>
152
+ </widget>
153
+ <packing>
154
+ <property name="expand">False</property>
155
+ <property name="position">1</property>
156
+ </packing>
157
+ </child>
158
+ </widget>
159
+ <packing>
160
+ <property name="position">1</property>
161
+ </packing>
162
+ </child>
163
+ <child>
164
+ <widget class="GtkLabel" id="label2">
165
+ <property name="visible">True</property>
166
+ <property name="label" translatable="yes">page 2</property>
167
+ </widget>
168
+ <packing>
169
+ <property name="type">tab</property>
170
+ <property name="position">1</property>
171
+ <property name="tab_fill">False</property>
172
+ </packing>
173
+ </child>
174
+ </widget>
175
+ </child>
176
+ </widget>
177
+ </child>
178
+ </widget>
179
+ </child>
180
+ </widget>
181
+ <packing>
182
+ <property name="position">2</property>
183
+ </packing>
184
+ </child>
185
+ <child>
186
+ <widget class="GtkAlignment" id="alignment3">
187
+ <property name="visible">True</property>
188
+ <child>
189
+ <widget class="GtkToolbar" id="toolbar1">
190
+ <property name="visible">True</property>
191
+ <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
192
+ <child>
193
+ <widget class="GtkToolButton" id="toolbutton1">
194
+ <property name="visible">True</property>
195
+ <property name="stock_id">gtk-yes</property>
196
+ <signal name="clicked" handler="onKnown"/>
197
+ </widget>
198
+ <packing>
199
+ <property name="expand">False</property>
200
+ </packing>
201
+ </child>
202
+ <child>
203
+ <widget class="GtkToolButton" id="toolbutton2">
204
+ <property name="visible">True</property>
205
+ <property name="stock_id">gtk-dialog-error</property>
206
+ <signal name="clicked" handler="onUnknown"/>
207
+ </widget>
208
+ <packing>
209
+ <property name="expand">False</property>
210
+ </packing>
211
+ </child>
212
+ <child>
213
+ <widget class="GtkSeparatorToolItem" id="toolbutton3">
214
+ <property name="visible">True</property>
215
+ </widget>
216
+ <packing>
217
+ <property name="expand">False</property>
218
+ <property name="homogeneous">False</property>
219
+ </packing>
220
+ </child>
221
+ <child>
222
+ <widget class="GtkToolButton" id="toolbutton6">
223
+ <property name="visible">True</property>
224
+ <property name="stock_id">gtk-dialog-info</property>
225
+ <signal name="clicked" handler="onHelp"/>
226
+ </widget>
227
+ <packing>
228
+ <property name="expand">False</property>
229
+ </packing>
230
+ </child>
231
+ <child>
232
+ <widget class="GtkSeparatorToolItem" id="toolbutton7">
233
+ <property name="visible">True</property>
234
+ </widget>
235
+ <packing>
236
+ <property name="expand">False</property>
237
+ <property name="homogeneous">False</property>
238
+ </packing>
239
+ </child>
240
+ <child>
241
+ <widget class="GtkToolButton" id="toolbutton5">
242
+ <property name="visible">True</property>
243
+ <property name="stock_id">gtk-edit</property>
244
+ <signal name="clicked" handler="onEdit"/>
245
+ </widget>
246
+ <packing>
247
+ <property name="expand">False</property>
248
+ </packing>
249
+ </child>
250
+ <child>
251
+ <widget class="GtkToolButton" id="toolbutton4">
252
+ <property name="visible">True</property>
253
+ <property name="stock_id">gtk-quit</property>
254
+ <signal name="clicked" handler="onQuit"/>
255
+ </widget>
256
+ <packing>
257
+ <property name="expand">False</property>
258
+ </packing>
259
+ </child>
260
+ </widget>
261
+ </child>
262
+ </widget>
263
+ <packing>
264
+ <property name="expand">False</property>
265
+ <property name="position">3</property>
266
+ </packing>
267
+ </child>
268
+ </widget>
269
+ </child>
270
+ </widget>
271
+ </glade-interface>
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,62 @@
1
+ #! /usr/bin/ruby
2
+
3
+ # Copyright 2008 Burghard Oliver
4
+ #
5
+ # This file is part of KeepYourHead.
6
+ #
7
+ # KeepYourHead is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # KeepYourHead is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with KeepYourHead. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'fileutils.rb'
21
+
22
+ require File.expand_path( "Keepyourhead/Utils.rb", File.dirname(__FILE__) )
23
+ requireExp "Resources.rb"
24
+
25
+ requireExp "Preferences.rb"
26
+
27
+ requireExp "style/Style.rb"
28
+ requireExp "style/StyleLatex.rb"
29
+
30
+ requireExp "Compilation.rb"
31
+ requireExp "Images.rb"
32
+ requireExp "Cache.rb"
33
+ requireExp "Training.rb"
34
+
35
+ requireExp "database/XmlAccessor.rb"
36
+ requireExp "database/BaseStatistic.rb"
37
+ requireExp "database/Base.rb"
38
+ requireExp "database/BaseTopicFlashcardContainer.rb"
39
+ requireExp "database/Database.rb"
40
+ requireExp "database/Collection.rb"
41
+ requireExp "database/File.rb"
42
+ requireExp "database/FileRoot.rb"
43
+ requireExp "database/Flashcard.rb"
44
+ requireExp "database/Topic.rb"
45
+ requireExp "database/Visitor.rb"
46
+
47
+ requireExp "gui/Action.rb"
48
+ requireExp "gui/WindowEditAdapters.rb"
49
+ requireExp "gui/WindowEdit.rb"
50
+ requireExp "gui/WindowEditActions.rb"
51
+ requireExp "gui/DialogEditLatex.rb"
52
+ requireExp "gui/DialogEditText.rb"
53
+ requireExp "gui/WindowTrain.rb"
54
+ requireExp "gui/DialogTrainStart.rb"
55
+
56
+ requireExp "gui/FlashcardViewController.rb"
57
+
58
+
59
+ requireExp "Version.rb"
60
+ requireExp "Application.rb"
61
+
62
+
@@ -0,0 +1,94 @@
1
+ # Copyright 2008 Burghard Oliver
2
+ #
3
+ # This file is part of KeepYourHead.
4
+ #
5
+ # KeepYourHead is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # KeepYourHead is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with KeepYourHead. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module KeepYourHead
19
+ class Application < Gnome::App
20
+ Opts = GetoptLong.new(
21
+ [ '--edit', '-e', GetoptLong::OPTIONAL_ARGUMENT ],
22
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
23
+ [ '--train', "-t", GetoptLong::OPTIONAL_ARGUMENT ]
24
+ )
25
+
26
+ def initialize
27
+ print Project::BANNER
28
+
29
+ #Gdk::Threads.init
30
+ Gnome::Program.new( Project::NAME, Project::VERSION)
31
+ Gtk.init
32
+
33
+ # @start = "welcome"
34
+ @start = "edit"
35
+
36
+ @filename = "database.xfc"
37
+
38
+ Opts.each{ |opt,arg|
39
+ case opt
40
+ when "--edit"
41
+ @start = "edit"
42
+ @filename = arg if arg
43
+ when "--train"
44
+ @start = "train"
45
+ @filename = arg if arg
46
+ when "--help"
47
+ puts <<-endl
48
+ ...asdasd
49
+ endl
50
+ end
51
+ }
52
+
53
+ # $width = 800
54
+ # $width = (Gdk::Screen.default.width * 0.7).to_i
55
+
56
+ $cache = Cache.new
57
+
58
+ $preferences = Preferences.new
59
+ $database = Database::Database.new
60
+
61
+
62
+ case @start
63
+ when "train"
64
+ DialogQuestionStart.new
65
+ when "edit"
66
+ WindowEdit.new $database
67
+ end
68
+ end
69
+
70
+ def quit
71
+ $cache.writeBack
72
+ $cache = nil
73
+
74
+ $database.writeBack
75
+ $database = nil
76
+
77
+ $preferences.writeBack
78
+ $preferences = nil
79
+
80
+ Gtk.main_quit
81
+ end
82
+
83
+ def mainloop
84
+ Gtk.main
85
+ end
86
+
87
+ def self.run
88
+ $application = Application.new
89
+ $application.mainloop
90
+ end
91
+ end
92
+
93
+ end
94
+
@@ -0,0 +1,233 @@
1
+ # Copyright 2008 Burghard Oliver
2
+ #
3
+ # This file is part of KeepYourHead.
4
+ #
5
+ # KeepYourHead is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # KeepYourHead is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with KeepYourHead. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+
19
+ module KeepYourHead
20
+ class CacheItem
21
+ attr_accessor :cache, :success, :filenames, :size, :lastAccess
22
+
23
+ def initialize(cache, success, filenames, lastAccess)
24
+ self.cache, self.success,self.filenames, self.lastAccess = cache, success, filenames, lastAccess
25
+
26
+ calculateSize
27
+ end
28
+
29
+ def calculateSize
30
+ self.size = (self.filenames && self.filenames.map { |filename| ::File.size?(filename) }.inject(0) { |a,b| a + b }) || 0
31
+ end
32
+
33
+ def ok?
34
+ self.filenames.map{ |filename|
35
+ File.exist?(filename)
36
+ }.inject(true) { |a,b| a and b }
37
+ end
38
+
39
+ def old?
40
+ now = Time.new
41
+
42
+ now - self.lastAccess > Cache::MaxAge
43
+ end
44
+
45
+ def remove
46
+ @cache.delete key
47
+
48
+ filenames.each { |filename|
49
+ File.delete filename if File.exist?(filename)
50
+ }
51
+ end
52
+ end
53
+
54
+ class Cache
55
+ CachePath = Resources::user("cache/")
56
+ Filename = ::File.expand_path( "index.yaml", CachePath )
57
+
58
+
59
+ attr_accessor :cacheSize
60
+
61
+ def initialize
62
+ @monitor = Monitor.new
63
+ load
64
+ end
65
+
66
+ def load
67
+ lock {
68
+ @cache = {}
69
+ begin
70
+ data = []
71
+ File.open( Filename, "r") {|file|
72
+ data = YAML.load( file )
73
+ }
74
+
75
+ # pp data.inspect
76
+ data.each { |key, success, filenames,lastAccess|
77
+ item = CacheItem.new self, success, filenames || [], Time.parse(lastAccess)
78
+ if item and item.ok? then
79
+ @cache[key] = item
80
+ end
81
+ }
82
+
83
+ # print "Cache loaded #{@cache.length} items"
84
+ rescue Errno::ENOENT
85
+ @cache = {}
86
+ print "Cache not found - recreating"
87
+ end
88
+
89
+ cleanUp
90
+
91
+ checkSize
92
+ }
93
+ end
94
+
95
+ def writeBack
96
+ lock {
97
+ cleanUp
98
+ removeOld
99
+ checkSize
100
+
101
+ ::File.mkdirs CachePath unless ::File.directory? CachePath
102
+
103
+ ::File.open( Filename, "w" ) { |file|
104
+ data = []
105
+ @cache.each { |key,item|
106
+ data << [key, item.success, item.filenames, item.lastAccess.to_s]
107
+ }
108
+ file << data.to_yaml
109
+ # YAML::dump(data, file)
110
+ }
111
+ }
112
+ end
113
+
114
+ MaxAge = 2 * 30 * 24 * 60 * 60 #60 days
115
+ MaxSize = 25 * 1024 * 1024 # 25 mb
116
+ # MaxSize = 20 * 1024; #20 kb
117
+
118
+
119
+ def getCacheItem( flashcard, type, compileOptions = {}, &block)
120
+ width ||= Gdk::Screen.default.width
121
+ if not hasCacheItem( flashcard, type, compileOptions, &block ) then
122
+ compilation = flashcard.compileImage( type, compileOptions )
123
+ addCompilation( compilation )
124
+ ret = hasCacheItem( flashcard, type, compileOptions, &block )
125
+ compilation.remove
126
+
127
+ assert ret
128
+ end
129
+ end
130
+
131
+ def hasCacheItem( flashcard, type, compileOptions = {}, &block )
132
+ item = nil
133
+
134
+ content = flashcard.content(type, compileOptions)
135
+ lock {
136
+ item = @cache[content]
137
+
138
+ item.lastAccess = Time.new if item
139
+
140
+ block.call(item) if block
141
+ }
142
+
143
+ not item == nil
144
+ end
145
+
146
+ def addCompilation( compilation )
147
+ if compilation.success then
148
+ filenames = compilation.filenames.map { |filename| fnew = createNewFilename; ::FileUtils.cp(filename, fnew); fnew }
149
+
150
+ item = CacheItem.new self, true, filenames, Time.new
151
+ else
152
+ item = CacheItem.new self, false, [], Time.new
153
+ end
154
+
155
+ lock {
156
+ @cache[compilation.content] = item
157
+ self.cacheSize += item.size if self.cacheSize
158
+ }
159
+
160
+ checkSize
161
+ end
162
+
163
+
164
+ private
165
+ def lock
166
+ @monitor.mon_synchronize {
167
+ yield
168
+ }
169
+ end
170
+
171
+ def removeOld
172
+ now = Time.new
173
+
174
+ @cache.each { |key, item|
175
+ if item.old? then
176
+ item.remove
177
+ end
178
+ }
179
+ end
180
+
181
+ def cleanUp
182
+ @cache.each { |key, item|
183
+ if not item.ok? then
184
+ item.remove
185
+ end
186
+ }
187
+
188
+ files = @cache.values.map {|item| item.filenames }.flatten.to_set
189
+ Dir.new( CachePath ).each { |filename|
190
+ next if filename == "." or filename == ".." or filename == "index.yaml"
191
+
192
+ filename = ::File.expand_path( filename, CachePath )
193
+ if not files.include? filename then
194
+ File.delete filename
195
+ # puts "image in dir, not in cache #{filename}"
196
+ end
197
+ }
198
+ end
199
+
200
+ def checkSize
201
+ if not self.cacheSize or self.cacheSize > MaxSize then
202
+ self.cacheSize = @cache.values.map{ |item| item.size }.inject(0) {|v,a| v+a}
203
+ order = @cache.keys.sort { |k1,k2| @cache[k2].lastAccess <=> @cache[k1].lastAccess }
204
+ while self.cacheSize > MaxSize do
205
+ v = order.pop
206
+
207
+ # puts "remove #{@cache[v].filename}"
208
+
209
+ self.cacheSize -= @cache[v].size
210
+ @cache[v].remove
211
+ end
212
+ end
213
+ end
214
+
215
+ def createNewFilename
216
+ filename = nil
217
+
218
+ @monitorNewFilename ||= Monitor.new
219
+ @monitorNewFilename.mon_synchronize {
220
+ begin
221
+ i = rand(10000000)
222
+ filename = ::File.expand_path( "img_#{i}.png", CachePath )
223
+ end while File.exist? filename
224
+
225
+ assert filename
226
+ }
227
+
228
+ filename
229
+ end
230
+
231
+ end
232
+
233
+ end