Scid  4.6.5
metadata.tcl
Go to the documentation of this file.
1 ###
2 ### metadata.tcl: part of Scid.
3 ### Copyright (C) 2008 Alexander Wagner
4 ###
5 ### $Id: metadata.tcl,v 4.3 2011/02/13 18:12:02 arwagner Exp $
6 ###
7 ### Last change: <Fri, 2008/12/26 13:08:31 arwagner ingata>
8 ###
9 ### Read/Write/Show descriptive information for a specific database
10 ###
11 #======================================================================
12 
13 set m .menu.tools
14 
15 # $m add command -label "Database information..." -command {::metadata::show}
16 
17 #======================================================================
18 #
19 #======================================================================
20 namespace eval metadata {
21 
22  set metadatafilename ""
23  set DBMetadata ""
24 
25  # preset the data hash with the usual Dublin Core values
26  set datahash(dc:title) ""
27  set datahash(dc:description) ""
28  set datahash(dc:date) ""
29  set datahash(dc:subject) ""
30  set datahash(dc:type) "Dataset"
31  set datahash(dc:source) ""
32  set datahash(dc:coverage) ""
33  set datahash(dc:creator) "Shanes Chess Information Database (Scid) $::scidVersion"
34  set datahash(dc:rights) ""
35  set datahash(dc:format) "application/sciddb"
36  set datahash(dc:identifier) ""
37  set datahash(dc:language) ""
38  set datahash(dc:audience) ""
39  set datahash(dc:provenance) ""
40  set datahash(dc:rightsholder) ""
41  set datahash(dc:instructionalmethod) ""
42  set datahash(dc:accrualmethos) ""
43  set datahash(dc:accrualperiodicity) ""
44  set datahash(dc:accrualpolidy) ""
45 
46 
47  #----------------------------------------------------------------------
48  # Store the metadata to a Scid config file.
49  #----------------------------------------------------------------------
50  proc saveOptions {metadatafile} {
51 
52  set optionF ""
53 
54  # Copy data back from the hash to the list
55  set ::metadata::DBMetadata ""
56  foreach key [array names ::metadata::datahash *] {
57  lappend ::metadata::DBMetadata [list $key $::metadata::datahash($key)]
58  }
59 
60  if {[catch {open $metadatafile w} optionF]} {
61  tk_messageBox -title "Scid: Unable to write file" -type ok -icon warning \
62  -message "Unable to write options file: $metadatafile\n$optionF"
63  } else {
64  puts $optionF "# Scid options file"
65  puts $optionF "# Version: $::scidVersion, $::scidVersionDate"
66  puts $optionF "#"
67  puts $optionF "# Descriptive Metadata"
68  puts $optionF "# This file is generated automatically. Do NOT edit."
69 
70  set curtime [clock format [clock seconds]]
71  puts $optionF "#"
72  puts $optionF "# Last Update: $curtime"
73  puts $optionF "#"
74 
75  foreach i {::metadata::DBMetadata } {
76  puts $optionF "set $i [list [set $i]]"
77  }
78  close $optionF
79  }
80 
81  # now write also a Dublin Core XML file
82  regsub "sme$" $metadatafile "sg3" dbname
83  regsub "sme$" $metadatafile "xml" metadatafile
84  if {[catch {open $metadatafile w} optionF]} {
85  tk_messageBox -title "Scid: Unable to write file" -type ok -icon warning \
86  -message "Unable to write options file: $metadatafile\n$optionF"
87  } else {
88  puts $optionF "<rdf:RDF"
89  puts $optionF " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
90  puts $optionF " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"
91  puts $optionF " <rdf:Description rdf:about=\"$dbname\">"
92  foreach key [array names ::metadata::datahash *] {
93  puts $optionF " <$key>$::metadata::datahash($key)</$key>"
94  }
95  puts $optionF " </rdf:Description>"
96  puts $optionF "</rdf:RDF>"
97  close $optionF
98  }
99  }
100 
101  #----------------------------------------------------------------------
102  # Show the current metadata from the sme file and allow to edit
103  # them. If no metadata are found use sensible defaults.
104  #----------------------------------------------------------------------
105  proc show {} {
106 
107  if { [sc_base current] < 9 } {
108 
109  set w .metadataWindow
110  if {[winfo exists .metadataWindow]} {
111  focus .
112  destroy .metadataWindow
113  return
114  }
115 
116  toplevel $w
117  wm title $w "Database Information"
118  # the window is not resizable
119  ### wm resizable $w 0 0
120 
121  set currentdb [sc_base current]
122  set metadatafile [file nativename [sc_base filename $currentdb]]
123 
124  set metadatafile "$metadatafile.sme"
125  puts $metadatafile
126 
127  # set sensible defaults
128  set ::metadata::DBMetadata ""
129  set ::metadata::datahash(dc:title) [file tail [sc_base filename $currentdb]]
130  set ::metadata::datahash(dc:description) ""
131  set ::metadata::datahash(dc:date) [clock format [clock seconds]]
132  set ::metadata::datahash(dc:subject) ""
133  set ::metadata::datahash(dc:type) "Dataset"
134  set ::metadata::datahash(dc:source) ""
135  set ::metadata::datahash(dc:coverage) ""
136  set ::metadata::datahash(dc:creator) "Shanes Chess Information Database (Scid) $::scidVersion"
137  set ::metadata::datahash(dc:rights) ""
138  set ::metadata::datahash(dc:format) "application/sciddb"
139  set ::metadata::datahash(dc:identifier) ""
140  set ::metadata::datahash(dc:language) ""
141  set ::metadata::datahash(dc:audience) ""
142  set ::metadata::datahash(dc:provenance) ""
143  set ::metadata::datahash(dc:rightsholder) ""
144  set ::metadata::datahash(dc:instructionalmethod) ""
145  set ::metadata::datahash(dc:accrualmethos) ""
146  set ::metadata::datahash(dc:accrualperiodicity) ""
147  set ::metadata::datahash(dc:accrualpolidy) ""
148 
149  # hook up with scid's geometry manager
150  setWinLocation $w
151  setWinSize $w
152  bind $w <Configure> "recordWinSize $w"
153 
154  set ::metadata::metadatafilename $metadatafile
155 
156  button $w.bOk -text OK -command {
157  ::metadata::saveOptions $::metadata::metadatafilename
158  destroy .metadataWindow
159  }
160  button $w.bCancel -text [::tr "Cancel"] -command "destroy $w"
161 
162  # enable the standard shortcuts
164 
165  set textcolour "black"
166  if {[catch {source $metadatafile}]} {
167  # copy default values if there is no set
168  foreach key [array names ::metadata::datahash *] {
169  lappend ::metadata::DBMetadata [list $key $::metadata::datahash($key)]
170  }
171  set textcolour "blue"
172  }
173 
174  set line 0
175 
176  foreach i $metadata::DBMetadata {
177 
178  set tag [lindex $i 0]
179  set val [lindex $i 1]
180 
181  label $w.$tag -fg $textcolour -text $tag
182  set ::metadata::datahash($tag) $val
183 
184  entry $w.v$tag -width 60 -textvariable "::metadata::datahash($tag)"
185 
186  grid $w.$tag -stick w -column 0 -row $line
187  grid $w.v$tag -stick w -column 1 -row $line
188 
189  set line [expr {$line + 1 }]
190  }
191 
192  # Buttons and ESC-key
193  grid $w.bOk -stick e -column 0 -row $line -pady 10
194  grid $w.bCancel -column 1 -row $line -pady 10
195  bind $w <Escape> "$w.bCancel invoke"
196 
197  bind $w <F1> { helpWindow Metadata}
198  }
199 
200  }
201 
202 }
203 
204