jota 0.8.0 → 0.8.1

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.
data/INSTALL CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- $Id: INSTALL 37 2009-02-09 10:06:02Z dz $
2
+ $Id: INSTALL 39 2009-02-17 10:19:31Z dz $
3
3
 
4
4
  Jota is a written in the Ruby programming language and uses GTK+ Widgets.
5
5
 
@@ -79,11 +79,11 @@ For the common operating systems you can use the following command:
79
79
  Windows of course has no sophisticated package management. You have to
80
80
  download and install the following by hand.
81
81
 
82
- Go to http://ruby-gnome2.sourceforge.jp/#Ruby-GNOME2+Win32+GUI+Installer
82
+ Go to http://ruby-gnome2.sourceforge.jp/hiki.cgi?Install+Guide+for+Windows
83
83
  and follow the three steps. In short:
84
84
 
85
85
  1. install http://rubyforge.org/frs/download.php/17357/ruby185-22.exe
86
- (enable RubyGems)
86
+ (enable RubyGems). Install into default installation diectory.
87
87
  2. install http://prdownloads.sourceforge.net/ruby-gnome2/ruby-gnome2-0.16.0-1-i386-mswin32.exe?download
88
88
 
89
89
 
@@ -98,6 +98,10 @@ alternatively, download jota-$VERSION.gem and install it with
98
98
 
99
99
  gem install jota-$VERSION.gem
100
100
 
101
+ On Windows Vista you must execute gem as administrator. To do so enter
102
+ "gem install jota" in the run box (Start menu, at the bottom) and hit
103
+ Ctrl-Shift-Enter. Then accept the UAC dialog with "Continue".
104
+
101
105
  If you get the error "ERROR: While executing gem ... (RuntimeError)" and
102
106
  "jota requires cmd >= 0.7.2", you have an older version of gems that does not
103
107
  resolve dependencies on its own.
data/bin/jota CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # $Id: jota 28 2009-01-22 09:20:48Z dz $
3
+ # $Id: jota 45 2009-05-08 09:27:26Z dz $
4
4
 
5
5
  begin
6
6
  require 'jota'
@@ -9,4 +9,4 @@ rescue LoadError
9
9
  require 'jota'
10
10
  end
11
11
 
12
- Jota.new.run_gui
12
+ Jota.new.run
data/lib/cli.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # $Id: cli.rb 37 2009-02-09 10:06:02Z dz $
2
+ # $Id: cli.rb 46 2009-05-08 09:27:55Z dz $
3
3
 
4
4
  # if you use vim and don't like folds type zR
5
5
 
@@ -57,7 +57,7 @@ def do_create(args)
57
57
  @data.close if @data
58
58
  begin
59
59
  @data = ClipArray.create(filename)
60
- rescue AppError => msg
60
+ rescue SystemCallError, AppError => msg
61
61
  puts msg
62
62
  @data = nil
63
63
  end
@@ -80,33 +80,7 @@ def do_edit(args)
80
80
  index = get_index(args)
81
81
  return if index.nil?
82
82
 
83
- file = Tempfile.new("jotacli")
84
- filename = file.path
85
- print_verbose "creating temporary file '#{filename}'"
86
-
87
- file.puts @data[index].title
88
- file.puts @data[index].data
89
- file.close
90
-
91
- if ENV["EDITOR"] then
92
- cmdline = ENV["EDITOR"]
93
- else
94
- cmdline = "/usr/bin/vi"
95
- end
96
- cmdline = "%s %s" % [cmdline, filename]
97
- print_verbose "executing '#{cmdline}'"
98
-
99
- if system(cmdline) then
100
- file = File.open(filename,"r")
101
- lines = file.readlines
102
- @data[index].title = lines[0].chomp
103
- @data[index].data = lines[1..lines.length-1].join("")
104
- file.close
105
- else
106
- puts "Error executing '#{cmdline}' with exit code #{$?}"
107
- end
108
-
109
- File.unlink(filename)
83
+ @data[index].text = editor(@data[index].text)
110
84
 
111
85
  # because of this save we do not not need autosave for the cli version
112
86
  @data.save
@@ -131,12 +105,11 @@ def do_delete(args)
131
105
  if pref("deletesave_enable") and not @data.current.empty? then
132
106
  deletefile = expand_filename(pref("deletesave_file"),
133
107
  @data.dirname, @data.filename)
134
- end
135
-
136
- begin
137
- @data.current.append_as_mbox(deletefile)
138
- rescue SystemCallError => msg
139
- puts msg
108
+ begin
109
+ @data.current.append_as_mbox(deletefile)
110
+ rescue SystemCallError => msg
111
+ puts msg
112
+ end
140
113
  end
141
114
 
142
115
  @data.delete
@@ -196,7 +169,7 @@ def setup
196
169
  puts "Type 'help' for commands"
197
170
 
198
171
  @data = nil
199
- @default_command = "page"
172
+ @default_command = "edit"
200
173
  end #}}}1
201
174
 
202
175
  def command_missing(command, args)
@@ -274,4 +247,4 @@ end #}}}1
274
247
 
275
248
  end # class
276
249
 
277
- # vim600: set foldmethod=marker:
250
+ # vim: set foldmethod=marker:
data/lib/clip.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # $Id: clip.rb 37 2009-02-09 10:06:02Z dz $
2
+ # $Id: clip.rb 46 2009-05-08 09:27:55Z dz $
3
3
 
4
4
  # if you use vim and don't like folds type zR
5
5
 
@@ -35,6 +35,7 @@ def Clip.from_mbox(str)
35
35
  # "From_" line already removed
36
36
  cl = Clip.new
37
37
  in_header = true
38
+ charset = nil
38
39
  str.each_line do | line |
39
40
  if in_header then
40
41
  if line == "\n" then
@@ -46,10 +47,10 @@ def Clip.from_mbox(str)
46
47
  (key, value) = line.split(/\s*: /,2)
47
48
  value.chomp!
48
49
  case key.downcase
49
- when "x-wrap"
50
- cl.wrap = (value.downcase == "true")
50
+ when "x-flags"
51
+ cl.wrap = value.downcase.include?("w")
51
52
  when "subject"
52
- cl.title = value
53
+ cl.title,charset = q_decode(value)
53
54
  when "date"
54
55
  cl.created = Time.parse(value)
55
56
  when "content-type"
@@ -72,19 +73,29 @@ end #}}}1
72
73
  def to_mbox
73
74
  #{{{1
74
75
  str = ""
76
+ charset = "UTF-8"
77
+
75
78
  str << "Date: %s\n" % @created.ctime
76
- str << "Subject: %s\n" % @title
79
+
80
+ str << "Subject: %s\n" % [q_encode(charset,@title)]
81
+
77
82
  case @type
78
83
  when :text
79
- str << "Content-Type: text/plain\n"
84
+ str << "Content-Type: text/plain; charset=#{charset}\n"
80
85
  when :pref
81
86
  str << "Content-Type: application/x-jota-pref\n"
82
87
  end
83
- str << "X-Wrap: %s\n" % @wrap.to_s
84
- str << "X-Saved-By: %s %s\n" % [
88
+
89
+ str << "X-Flags: "
90
+ str << "w" if @wrap
91
+ str << "\n"
92
+
93
+ str << "Originating-Client: %s %s\n" % [
85
94
  Version::PROGRAM_NAME, Version::STRING]
86
95
  str << "\n"
96
+
87
97
  str << @data
98
+
88
99
  return str
89
100
  end #}}}1
90
101
 
@@ -114,6 +125,7 @@ end #}}}1
114
125
 
115
126
  def append_as_mbox(file_and_path)
116
127
  #{{{1
128
+ print_verbose "append to mbox '#{file_and_path}'"
117
129
  File.open(file_and_path,"a") do | f |
118
130
  f.print "From %s@localhost %s\n" %
119
131
  [Version::PROGRAM_NAME, Time.now.ctime]
@@ -132,6 +144,42 @@ def ==(clip)
132
144
  return self.to_hash == clip.to_hash
133
145
  end #}}}1
134
146
 
147
+ # POSSIBLE CASES FOR TEXT <-> TITLE/DATA CONVERSION
148
+ # # {{{1
149
+ # # text title data
150
+ # # a) "" 1) "" ""
151
+ # # b) abc 2) abc ""
152
+ # # c) abc\n 2) abc ""
153
+ # # d) abc\n 3) abc def\n
154
+ # # def
155
+ # # e) abc\n 3) abc def\n
156
+ # # def\n
157
+ # # }}}1
158
+
159
+ def text
160
+ #{{{1
161
+ if @title == "" and @data == "" then
162
+ # map (1) to (a)
163
+ return ""
164
+ else
165
+ # map (2) to (b) and (3) to (d)
166
+ return "%s\n%s" % [@title,@data]
167
+ end
168
+ end #}}}1
169
+
170
+ def text=(str)
171
+ # {{{1
172
+ # map (a),(b) to (c) and (d) to (e)
173
+ str = str.chomp + "\n"
174
+
175
+ # map (c) to (2) and (e) to (3)
176
+ arr = str.split("\n",-1) # arr has at least 2 elems
177
+ # the last elem is empty
178
+ @title = arr[0] # first elem = first line
179
+ @data = arr[1..-1].join("\n") # second to last elem
180
+ end #}}}1
181
+
182
+
135
183
  end #class
136
184
 
137
- # vim600: set foldmethod=marker:
185
+ # vim: set foldmethod=marker:
data/lib/clip_array.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # $Id: clip_array.rb 37 2009-02-09 10:06:02Z dz $
2
+ # $Id: clip_array.rb 53 2009-09-24 14:22:04Z dz $
3
3
 
4
4
  # if you use vim and don't like folds type zR
5
5
 
@@ -111,6 +111,20 @@ end #}}}1
111
111
  # end
112
112
  #end #}}}1
113
113
 
114
+ def goto_regexp(re)
115
+ #{{{1
116
+ if re =~ /^\s*\d+\s*$/ then
117
+ self.current_index = re.to_i-1
118
+ else
119
+ self.each_index do | i |
120
+ if self[i].title.match(re) then
121
+ @current_index = i
122
+ break
123
+ end
124
+ end
125
+ end
126
+ end #}}}1
127
+
114
128
  def current_index=(num)
115
129
  #{{{1
116
130
  if num < 0 then
@@ -214,7 +228,7 @@ end #}}}1
214
228
 
215
229
  def ClipArray.create(file_and_path)
216
230
  #{{{1
217
- print_verbose "creating file '#{file_and_path}"
231
+ print_verbose "creating file '#{file_and_path}'"
218
232
 
219
233
  if File.exists?(file_and_path) then
220
234
  raise AppError, "File '#{file_and_path}' already exists"
@@ -292,13 +306,13 @@ def autosave(seconds)
292
306
  #{{{1
293
307
  print_debug "autosave(#{seconds}) called"
294
308
  if @autosave_thread then
295
- print_debug " killing old thread"
309
+ print_debug " killing old thread"
296
310
  @autosave_thread.kill
297
311
  @autosave_thread = nil
298
312
  end
299
313
 
300
314
  if seconds == 0 then
301
- print_debug " returning because seconds==0"
315
+ print_debug " returning because seconds==0"
302
316
  return
303
317
  end
304
318
 
@@ -390,4 +404,4 @@ end #}}}1
390
404
 
391
405
  end # class
392
406
 
393
- # vim600: set foldmethod=marker:
407
+ # vim: set foldmethod=marker:
data/lib/gui.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # $Id: gui.rb 37 2009-02-09 10:06:02Z dz $
3
+ # $Id: gui.rb 53 2009-09-24 14:22:04Z dz $
4
4
 
5
5
  # if you use vim and don't like folds type zR
6
6
 
@@ -71,14 +71,10 @@ def close
71
71
  end
72
72
  end #}}}1
73
73
 
74
- def set_current(regexp)
74
+ def goto_regexp(regexp)
75
75
  #{{{1
76
- return if @data.nil?
77
- @data.each_index do | i |
78
- if @data[i].title.match(regexp) then
79
- @data.current_index = i
80
- break
81
- end
76
+ if @data then
77
+ @data.goto_regexp(regexp)
82
78
  end
83
79
  end #}}}1
84
80
 
@@ -92,7 +88,7 @@ def create_gui
92
88
 
93
89
  bindtextdomain(domain, localedir, nil, "UTF-8")
94
90
 
95
- print_verbose "loading glade spec from '#{glade_file}'"
91
+ print_verbose " loading glade spec from '#{glade_file}'"
96
92
  @glade = GladeXML.new(glade_file,
97
93
  nil,
98
94
  domain,
@@ -106,14 +102,15 @@ def create_gui
106
102
  @top_window = @glade.get_widget("top")
107
103
  @clip_widget = @glade.get_widget("clip")
108
104
 
105
+ clip_to_widget(@clip_widget,@data)
106
+
109
107
  # Show
108
+ print_debug " showing widgets"
110
109
  @top_window.show
111
110
  set_buttons
112
111
  set_style
113
112
  set_about_dialog
114
113
 
115
- # Show the first clip
116
- clip_to_widget(@clip_widget,@data)
117
114
  end #}}}1
118
115
 
119
116
 
@@ -414,6 +411,7 @@ end #}}}
414
411
 
415
412
  def on_edit_text_wrap_activate(widget)
416
413
  #{{{1
414
+ print_debug "on_edit_text_wrap_activate called"
417
415
  widget_to_clip(@clip_widget,@data)
418
416
  @data.current.wrap = @glade["edit_text_wrap"].active?
419
417
  clip_to_widget(@clip_widget,@data)
@@ -488,17 +486,36 @@ def set_goto_menu
488
486
 
489
487
  goto_menu = Gtk::Menu.new
490
488
  @data.each_index do | i |
489
+
490
+ if @data[i].title.length > 37 then
491
+ title = @data[i].title[0..36]+"..."
492
+ else
493
+ title = @data[i].title
494
+ end
495
+
496
+ # Using markup in a MenuItems is not implemented before
497
+ # GTK+ 2.16. Ruby GTK is 2.12 at the moment (2009-07).
498
+
499
+ #la = Gtk::Label.new
491
500
  if i == @data.current_index then
492
- marker = "<"
501
+ #title.gsub!(/</,"&lt;")
502
+ #title.gsub!(/>/,"&gt;")
503
+ #title.gsub!(/&/,"&amp;")
504
+ #la.markup = "<b>%2d: %s</b>" % [i, title]
505
+ marker = ">"
493
506
  else
494
- marker = ""
507
+ #la.text = "%2d: %s" % [i, title]
508
+ marker = " "
495
509
  end
496
510
 
497
- mi = Gtk::MenuItem.new("%2d: %s%s" %
498
- [i+1, @data[i].title, marker])
511
+ #mi = Gtk::MenuItem.new
512
+ #mi.label = la
513
+ mi = Gtk::MenuItem.new("%s%2d: %s" %
514
+ [marker, i+1, title])
499
515
  mi.signal_connect("activate") do
500
516
  on_menu_goto(i)
501
517
  end
518
+
502
519
  mi.show
503
520
  goto_menu.append(mi)
504
521
  end
@@ -552,6 +569,9 @@ end #}}}1
552
569
 
553
570
  def set_buttons
554
571
  #{{{1
572
+ #
573
+ # CAUTION: set_buttons may trigger callback functions "on_*"
574
+ #
555
575
  if @data.nil? then
556
576
  @glade["but_delete"].sensitive = false
557
577
  @glade["but_new"].sensitive = false
@@ -570,8 +590,9 @@ def set_buttons
570
590
  @glade["menu_export"].sensitive = false
571
591
  @glade["menu_import"].sensitive = false
572
592
 
573
- @top_window.title = "%s %s" %
574
- [Version::PROGRAM_NAME, Version::STRING]
593
+ @top_window.title = "%s %s" % [
594
+ Version::PROGRAM_NAME.capitalize,
595
+ Version::STRING]
575
596
  else
576
597
  @glade["but_delete"].sensitive = true
577
598
  @glade["but_new"].sensitive = true
@@ -602,10 +623,13 @@ def set_buttons
602
623
  @glade["menu_import"].sensitive = true
603
624
 
604
625
  if @data.current.title.strip.empty? then
605
- @top_window.title = "%s %s" %
606
- [Version::PROGRAM_NAME, Version::STRING]
626
+ @top_window.title = "%s %s" % [
627
+ Version::PROGRAM_NAME.capitalize,
628
+ Version::STRING]
607
629
  else
608
- @top_window.title = "%s" % [@data.current.title]
630
+ @top_window.title = "%s: %s" % [
631
+ Version::PROGRAM_NAME.capitalize,
632
+ @data.current.title]
609
633
  end
610
634
 
611
635
  set_goto_menu
@@ -696,40 +720,18 @@ def set_about_dialog
696
720
 
697
721
  end #}}}1
698
722
 
699
-
700
- # POSSIBLE CASES FOR CLIP TO/FROM WIDGET CONVERSION
701
- # {{{1
702
- # textview title data
703
- # a) "" 1) "" ""
704
- # b) abc 2) abc ""
705
- # c) abc\n 2) abc ""
706
- # d) abc\n 3) abc def\n
707
- # def
708
- # e) abc\n 3) abc def\n
709
- # def\n
710
- # }}}1
711
-
712
723
  def clip_to_widget(textview, clip_array)
713
724
  #{{{1
714
725
  print_debug "clip_to_widget"
715
726
  if clip_array.nil? then
716
- str = "#{Version::PROGRAM_NAME} #{Version::STRING} ready\n\n"+
727
+ str = "#{Version::PROGRAM_NAME.capitalize} #{Version::STRING} ready\n\n"+
717
728
  "Use Menu->New or Menu->Open\n"
718
729
  textview.buffer.text = str
719
730
  textview.editable = false
720
731
  else
721
732
  clip = clip_array.current
722
- print_debug " title='#{clip.title}'"
723
- print_debug " data='#{clip.data}'"
724
- if clip.title == "" and clip.data == "" then # map (1)
725
- str = "" # to (a)
726
- else
727
- # map (2) and (3) to (c) and (e) resp.
728
- str = "#{clip.title}\n#{clip.data}"
729
- print_debug " str='#{str}'"
730
- end
731
733
 
732
- textview.buffer.text = str
734
+ textview.buffer.text = clip.text
733
735
 
734
736
  if clip.pos then
735
737
  #mark = textview.buffer.get_insert
@@ -753,23 +755,7 @@ def widget_to_clip(textview, clip_array)
753
755
  #{{{1
754
756
  print_debug "widget_to_clip"
755
757
  if clip_array then
756
- str = textview.buffer.text
757
- print_debug " str='#{str}'"
758
-
759
- # map (a),(b) to (c) and (d) to (e)
760
- str = str.chomp + "\n"
761
- print_debug " str='#{str}'"
762
-
763
- # map (c) to (2) and (e) to (3)
764
- arr = str.split("\n",-1) # arr has at least 2 elems
765
- # the last elem is empty
766
- title = arr[0] # first elem = first line
767
- print_debug " title='#{title}'"
768
- data = arr[1..-1].join("\n") # second to last elem
769
- print_debug " data='#{data}'"
770
-
771
- clip_array.current.title = title
772
- clip_array.current.data = data
758
+ clip_array.current.text = textview.buffer.text
773
759
  clip_array.current.pos = textview.buffer.cursor_position
774
760
 
775
761
  if textview.wrap_mode == Gtk::TextTag::WRAP_NONE then
@@ -789,4 +775,4 @@ end #}}}1
789
775
 
790
776
  end # Class
791
777
 
792
- # vim600: set foldmethod=marker:
778
+ # vim: set foldmethod=marker:
data/lib/helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # $Id: helper.rb 37 2009-02-09 10:06:02Z dz $
2
+ # $Id: helper.rb 52 2009-09-24 14:17:25Z dz $
3
3
 
4
4
  # if you use vim and don't like folds type zR
5
5
 
@@ -14,7 +14,7 @@ def get_filename(filename, mode)
14
14
  action = Gtk::FileChooser::ACTION_OPEN
15
15
  ok_button = Gtk::Stock::OPEN
16
16
  else
17
- raise "Wrong mode #{mode} in helper:get_filenamen"
17
+ raise "Wrong mode #{mode} in helper:get_filename"
18
18
  end
19
19
 
20
20
  title = "Select Filename"
@@ -40,8 +40,6 @@ def get_filename(filename, mode)
40
40
  return
41
41
  end
42
42
 
43
- filename = Time.now.strftime(filename)
44
-
45
43
  return filename
46
44
  end #}}}1
47
45
 
@@ -74,7 +72,9 @@ def expand_filename(str, dirname, filename)
74
72
  result = Time.now.strftime(str)
75
73
  result = result.gsub(/\$f/,filename)
76
74
  result = result.gsub(/\$d/,dirname)
75
+ result = result.gsub(/\$p/,Process::pid.to_s)
77
76
  result = result.gsub(/\$\$/,"$")
77
+ print_debug "expanding '#{filename}' to '#{result}'"
78
78
  return result
79
79
  end #}}}1
80
80
 
@@ -115,15 +115,89 @@ end #}}}1
115
115
  def print_verbose(msg)
116
116
  #{{{1
117
117
  if $VERBOSE then
118
- puts "#{Process.pid}# #{msg}"
118
+ debug_file.puts "#{Process.pid}# #{msg}"
119
119
  end
120
120
  end #}}}1
121
121
 
122
+ def debug_file
123
+ if $debug_file.nil? then
124
+ begin
125
+ $debug_file = File.open($debug_filename,"w+")
126
+ rescue Exception => msg
127
+ $debug_file = $stdout
128
+ print_verbose "logging to '#{$debug_filename}' not possible: #{msg}"
129
+ end
130
+
131
+ end
132
+ return $debug_file
133
+ end
134
+
122
135
  def print_debug(msg)
123
136
  #{{{1
124
137
  if $DEBUG then
125
- puts "#{Process.pid}- #{msg}"
138
+ debug_file.puts "#{Process.pid}- #{msg}"
126
139
  end
127
140
  end #}}}1
128
141
 
129
- # vim600: set foldmethod=marker:
142
+ def editor(str)
143
+ #{{{1
144
+ file = Tempfile.new("jota")
145
+ filename = file.path
146
+ print_verbose "creating temporary file '#{filename}'"
147
+
148
+ file.puts str
149
+ file.close
150
+
151
+ if ENV["EDITOR"] then
152
+ cmdline = ENV["EDITOR"]
153
+ else
154
+ cmdline = "/usr/bin/vi"
155
+ end
156
+ cmdline = "%s %s" % [cmdline, filename]
157
+ print_verbose "executing '#{cmdline}'"
158
+
159
+ if system(cmdline) then
160
+ file = File.open(filename,"r")
161
+ lines = file.readlines.join("")
162
+ file.close
163
+ else
164
+ puts "Error executing '#{cmdline}' with exit code #{$?}"
165
+ lines = str
166
+ end
167
+
168
+ File.unlink(filename)
169
+
170
+ return lines
171
+ end #}}}1
172
+
173
+ def q_encode(charset,str)
174
+ #{{{1
175
+ #if str =~ /^[ -<>@-^`-~]*$/ then # all printable except "=?_"
176
+ if str =~ /[ -~]*/ then
177
+ result = str
178
+ else
179
+ encoded = [str].pack("M")
180
+ encoded.gsub!(/ /,"_")
181
+ encoded.gsub!(/\?/,"=3F")
182
+ encoded.sub!(/=$/,"")
183
+ result = "=?%s?Q?%s?=" % [charset, encoded]
184
+ end
185
+
186
+ return result
187
+ end #}}}1
188
+
189
+ def q_decode(str)
190
+ #{{{1
191
+ md = /^=\?(.*)?\?Q\?(.*?)\?=/i.match(str)
192
+ if md then
193
+ charset = md[1]
194
+ str.gsub!(/_/," ")
195
+ str = md[2].unpack("M").first
196
+ else
197
+ charset = nil
198
+ end
199
+
200
+ return str,charset
201
+ end #}}}1
202
+
203
+ # vim: set foldmethod=marker: