[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[mhc:02036] mhc2palm/palm2mhc のカテゴリパッチ
ちかごろPalmでテレビ番組予定をどんどん追加しているんですが
仕事の予定がみづらくなってきたのでカテゴリで分類しようとしてます。
palm2mhc/mhc2palmがカテゴリを扱えないので
みようみまねで扱えるようにしてみました。
ちなみにカテゴリを扱えるPalmアプリにはKsDatebookなどがあります。
とりあえずパッチを投げます。
#このパッチには以前に投げたのも含まれています
制約事項:
palmではカテゴリは1つだけ設定できますが
mhcでは複数指定できるので
mhc2palmではX-SC-Category:のなかで最初にpalmにカテゴリとして
登録されているものを設定するようにしました。
例えば、palmでカテゴリとしてFooとBarが登録されているときに
mhcの予定が
X-SC-Category: Hoge Bar Foo
となっていると、Bar が選択されます。
--
鯉江英隆 <hide@xxxxxxxx>
Index: mhc2palm.in
===================================================================
RCS file: /cvsroot/mhc/mhc2palm.in,v
retrieving revision 1.6
diff -u -r1.6 mhc2palm.in
--- mhc2palm.in 13 Sep 2001 05:15:17 -0000 1.6
+++ mhc2palm.in 22 Feb 2005 09:12:41 -0000
@@ -21,7 +21,7 @@
def usage
print '
-usage: mhc2palm [-a | -i] [-n] [-d dev] [-r dir] [YYYYMMDD-yyyymmdd]
+usage: mhc2palm [-a | -i] [-n] [-d dev] [-r dir] [-A mon] [-B mon] [YYYYMMDD-yyyymmdd]
mhc2palm -- Add/Copy mhc articles to a palm.
@@ -35,6 +35,8 @@
default value is /dev/pilot
-r dir : Set repository directory of the mhc.
~/Mail/schedule
+ -A mon : XXX
+ -B mon : XXX
YYYYMMDD-yyyymmdd : set a start and end date of scanning mhc.
if omitted, scan from 3 months ago to
@@ -69,6 +71,7 @@
$flag_verbose = false
$flag_noharm, $flag_append, $flag_install = false, false, false
$flag_device, $flag_from, $flag_to = '/dev/pilot', nil, nil
+$flag_before, $flag_after = -3, 3
$flag_dir = File .expand_path("~/Mail/schedule")
while ARGV .length > 0
@@ -87,6 +90,12 @@
when '-r'
ARGV .shift
$flag_dir = ARGV[0]
+ when '-A'
+ ARGV .shift
+ $flag_after = ARGV[0] . to_i
+ when '-B'
+ ARGV .shift
+ $flag_before = - (ARGV[0] . to_i)
when /^(\d{8})-(\d{8})$/
$flag_from, $flag_to = MhcDate .new($1), MhcDate .new($2)
else
@@ -95,8 +104,9 @@
ARGV .shift
end
-$flag_from = MhcDate .new .m_succ!(-3) if !$flag_from
-$flag_to = MhcDate .new .m_succ!(+3) if !$flag_to
+usage() if ($flag_before >= $flag_after)
+$flag_from = MhcDate .new .m_succ!($flag_before) if !$flag_from
+$flag_to = MhcDate .new .m_succ!($flag_after) if !$flag_to
usage() if !($flag_append || $flag_install) || ($flag_append && $flag_install)
@@ -105,7 +115,7 @@
##
if !$flag_noharm
- if !File .exist?($flag_device)
+ if $flag_device != "net:" && !File .exist?($flag_device)
STDERR .print "Can not open #{$flag_device}.\n"
exit 1
end
@@ -138,6 +148,9 @@
print "adding ", MhcKconv::todisp(sch .subject), "\n" if $flag_verbose
+ # XXX koie
+ sch .set_pilot_db(pdb)
+
if p_rec_array = sch .to_palm
if $flag_verbose
print " converted into #{p_rec_array .length} palm article#{p_rec_array .length == 1 ? '' : 's'}."
Index: palm2mhc.in
===================================================================
RCS file: /cvsroot/mhc/palm2mhc.in,v
retrieving revision 1.4
diff -u -r1.4 palm2mhc.in
--- palm2mhc.in 9 Feb 2001 09:37:06 -0000 1.4
+++ palm2mhc.in 22 Feb 2005 09:12:41 -0000
@@ -75,7 +75,7 @@
ARGV .shift
end
-if !File .exist?($flag_device)
+if $flag_device != "net:" && !File .exist?($flag_device)
STDERR .print "Can not open #{$flag_device}.\n"
exit 1
end
Index: ruby-ext/mhc_pilib.c
===================================================================
RCS file: /cvsroot/mhc/ruby-ext/mhc_pilib.c,v
retrieving revision 1.5
diff -u -r1.5 mhc_pilib.c
--- ruby-ext/mhc_pilib.c 15 Nov 2004 00:40:01 -0000 1.5
+++ ruby-ext/mhc_pilib.c 22 Feb 2005 09:12:41 -0000
@@ -491,6 +491,45 @@
return ary;
}
+/* XXX koie */
+static VALUE rpack_AppointmentAppInfo(VALUE o, VALUE ary1)
+{
+ struct AppointmentAppInfo ai;
+ unsigned char buf[0xffff];
+ int len;
+ VALUE ary = ary_new();
+ ary_copy(ary, ary1);
+
+ ar_get2(ary, "b", ai.category.renamed, 16);
+ ar_get2(ary, "c", ai.category.ID, 16);
+ ar_get1(ary, "c", ai.category.lastUniqueID);
+
+ ar_get1(ary, "i", ai.startOfWeek);
+
+ len = pack_AppointmentAppInfo(&ai, buf, sizeof(buf));
+ return str_new(buf, len);
+}
+
+
+/* XXX koie */
+static VALUE runpack_AppointmentAppInfo(VALUE o, VALUE raw_str)
+{
+ struct AppointmentAppInfo ai;
+ VALUE ary = ary_new();
+
+ Check_Type(raw_str, T_STRING);
+ unpack_AppointmentAppInfo(&ai, RSTRING(raw_str)->ptr, RSTRING(raw_str)->len);
+
+ ar_set2(ary, "b", ai.category.renamed, 16);
+ ar_set2(ary, "s16", ai.category.name, 16);
+ ar_set2(ary, "c", ai.category.ID, 16);
+ ar_set1(ary, "c", ai.category.lastUniqueID);
+
+ ar_set1(ary, "i", ai.startOfWeek);
+
+ return ary;
+}
+
/****************************************************************/
/********* For Address Records **********************************/
/****************************************************************/
@@ -541,6 +580,7 @@
ar_get1(ary, "c", ai.category.lastUniqueID);
ar_get2(ary, "s16", ai.labels, 22);
+ /* XXX koie ar_get2(ary, "b", ai.labelRenamed, 22) */
ar_get2(ary, "s16", ai.phoneLabels, 8);
ar_get1(ary, "i", ai.country);
ar_get1(ary, "b", ai.sortByCompany);
@@ -684,6 +724,9 @@
/* for datebook */
mfunc(mPiLib, "pack_Appointment", rpack_Appointment, 1);
mfunc(mPiLib, "unpack_Appointment", runpack_Appointment, 1);
+ /* XXX koie */
+ mfunc(mPiLib, "pack_AppointmentAppInfo", rpack_AppointmentAppInfo, 1);
+ mfunc(mPiLib, "unpack_AppointmentAppInfo", runpack_AppointmentAppInfo, 1);
/* for address */
mfunc(mPiLib, "pack_Address", rpack_Address, 1);
Index: ruby-ext/lib/mhc-palm.rb
===================================================================
RCS file: /cvsroot/mhc/ruby-ext/lib/mhc-palm.rb,v
retrieving revision 1.11
diff -u -r1.11 mhc-palm.rb
--- ruby-ext/lib/mhc-palm.rb 22 Jun 2004 10:09:15 -0000 1.11
+++ ruby-ext/lib/mhc-palm.rb 22 Feb 2005 09:12:42 -0000
@@ -93,6 +93,8 @@
def each_record
i = 0
while (rec = record_by_index(i)) != nil
+ # XXX koie
+ rec .set_pilot_db(self)
yield rec
i += 1
end
@@ -132,6 +134,10 @@
def get_app_info()
return PiLib .dlp_ReadAppBlock(@sd, @db)
end
+
+ def find_category(catname)
+ return -1
+ end
end
################################################################
@@ -143,10 +149,17 @@
class PilotRecord
def initialize(id = 0, attr = 0, category = 0, data = '')
@id, @attr, @category, @data = id, attr, category, data
+ # XXX koie
+ @pilot_db = nil
unpack
check
end
+ # XXX koie
+ def set_pilot_db(pilot_db)
+ @pilot_db = pilot_db
+ end
+
attr :id
def set_id(id)
raise "Integer required." if !(id .is_a?(Integer))
@@ -303,8 +316,29 @@
class PilotApptDB < PilotDB
def initialize(pi, dbname)
super
+
+ # XXX koie
+ app_info = self .get_app_info
+
+ @catRenamed, @catName, @catID, @catLastUniqueID,
+ # [22] [22] [8]
+ @startOfWeek = *PiLib .unpack_AppointmentAppInfo(app_info)
+
@recClass = PilotApptRecord
end
+ def get_catName(idx)
+ return @catName[idx]
+ end
+
+ # XXX koie
+ def find_category(catname)
+ for idx in 0 .. 15
+ if @catName[idx].capitalize == catname.capitalize
+ return idx
+ end
+ end
+ return -1
+ end
end
@@ -586,7 +620,16 @@
xsc["Subject"] = Kconv::tojis(Kconv::toeuc(@description) .sub(/\[[^\]]*\]\s*$/, ''))
xsc["Location"] = Kconv::tojis($1) if Kconv::toeuc(@description) =~ /\[([^\]]+)\]\s*$/
xsc["Note"] = Kconv::tojis(@note)
- xsc["Category"] = @category if category?
+ # XXX koie
+ #xsc["Category"] = @category if category?
+ if category?
+ catname = @pilot_db .get_catName(@category)
+ #STDERR .print "XXX: <#{@category}> <#{catname}>\n"
+ if catname == ""
+ catname = @category .to_s
+ end
+ xsc["Category"] = catname
+ end
xsc["Alarm"] = alarm
xsc["Day"] = @exception .collect{|t| '!' + t .to_xscday} .join(' ')
xsc["Day"] += ' ' + @beg .to_xscday if !repeat?
@@ -598,6 +641,16 @@
end
end
+ if attribute_secret?
+ if xsc["Category"]
+ if xsc["Category"] !~ /private/i
+ xsc["Category"] += ' Private'
+ end
+ else
+ xsc["Category"] = 'Private'
+ end
+ end
+
if repeat?
if @repeatFrequency > 1
STDERR .print "#{@beg} : #{Kconv::tojis(@description)} "
@@ -664,13 +717,10 @@
part1, part2 = string .split("\n\n", 2)
- if !(part1 =~ /^[ \t]+/ or part1 =~ /^[A-Za-z0-9_-]+:/)
- part1_is_header = false
- end
-
part1 .split("\n") .each{|line|
- if !(string =~ /^[ \t]+/ or string =~ /^[A-Za-z0-9_-]+:/)
- part1_is_header = false
+ if !(line =~ /^([ \t]|[A-Za-z][A-Za-z0-9_-]*:)/)
+ part1_is_header = false
+ break
end
}
Index: ruby-ext/lib/mhc-schedule.rb
===================================================================
RCS file: /cvsroot/mhc/ruby-ext/lib/mhc-schedule.rb,v
retrieving revision 1.21
diff -u -r1.21 mhc-schedule.rb
--- ruby-ext/lib/mhc-schedule.rb 25 Oct 2004 02:28:57 -0000 1.21
+++ ruby-ext/lib/mhc-schedule.rb 22 Feb 2005 09:12:42 -0000
@@ -195,6 +195,13 @@
end
set_rec_id(create_record_id) if ! rec_id
set_modified(false, 'initialize')
+ # XXX koie
+ @pilot_db = nil
+ end
+
+ # XXX koie
+ def set_pilot_db (pilot_db)
+ @pilot_db = pilot_db
end
################################################################
@@ -840,6 +847,22 @@
# STDERR .print "#{occur_min .to_js} : #{subject} unsupported. ignored..\n"
return nil
else
+ if category_as_string =~ /private/i
+ ret .each{|r|
+ r .set_attribute_secret
+ }
+ end
+ # XXX koie
+ category .each{|cat|
+ ### ret is an array of instance of PilotApptRecord
+ idx = @pilot_db .find_category(cat)
+ if idx >= 0
+ ret .each{|r|
+ r .set_category(idx)
+ }
+ break
+ end
+ }
return ret
end
end