~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/ruby/app_templates/kapp/app.rb

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=begin
 
2
  This class serves as the main window for %{APPNAME}.  It handles the
 
3
  menus, toolbars, and status bars.
 
4
 
 
5
  @short Main window class
 
6
  @author %{AUTHOR} <%{EMAIL}>
 
7
  @version %{VERSION}
 
8
=end
 
9
 
 
10
class %{APPNAMESC} < KDE::MainWindow
 
11
 
 
12
    slots 'fileNew()',
 
13
          'fileOpen()',
 
14
          'fileSave()',
 
15
          'fileSaveAs()',
 
16
          'filePrint()',
 
17
          'optionsPreferences()',
 
18
          'changeStatusbar(const QString&)',
 
19
          'changeCaption(const QString&)'
 
20
 
 
21
    def initialize()
 
22
        super( nil, "%{APPNAMESC}" )
 
23
        @view = %{APPNAMESC}View.new(self)
 
24
        @printer = nil
 
25
        # accept dnd
 
26
        setAcceptDrops(true)
 
27
    
 
28
        # tell the KDE::MainWindow that this is indeed the main widget
 
29
        setCentralWidget(@view)
 
30
    
 
31
        # then, setup our actions
 
32
        setupActions()
 
33
    
 
34
        # and a status bar
 
35
        statusBar().show()
 
36
    
 
37
        # Apply the create the main window and ask the mainwindow to
 
38
        # automatically save settings if changed: window size, toolbar
 
39
        # position, icon size, etc.  Also to add actions for the statusbar
 
40
        # toolbar, and keybindings if necessary.
 
41
        setupGUI();
 
42
    
 
43
        # allow the view to change the statusbar and caption
 
44
        connect(@view, SIGNAL('signalChangeStatusbar(const QString&)'),
 
45
                self,   SLOT('changeStatusbar(const QString&)'))
 
46
        connect(@view, SIGNAL('signalChangeCaption(const QString&)'),
 
47
                self,   SLOT('changeCaption(const QString&)'))
 
48
    
 
49
    end
 
50
    
 
51
    
 
52
    def load(url)
 
53
        target = ""
 
54
        # the below code is what you should normally do.  in this
 
55
        # example when, we want the url to our own.  you probably
 
56
        # want to use this code instead for your app
 
57
    
 
58
        if false
 
59
        # download the contents
 
60
        if KIO::NetAccess.download(url, target, self)
 
61
            # set our caption
 
62
            setCaption(url.url)
 
63
    
 
64
            # load in the file (target is always local)
 
65
            @view.openURL(KDE::URL.new(target))
 
66
    
 
67
            # and remove the temp file
 
68
            KIO::NetAccess.removeTempFile(target)
 
69
        end
 
70
        end
 
71
    
 
72
        setCaption(url.prettyURL())
 
73
        @view.openURL(url)
 
74
    end
 
75
    
 
76
    def setupActions()
 
77
        KDE::StdAction.openNew(self, SLOT('fileNew()'), actionCollection())
 
78
        KDE::StdAction.open(self, SLOT('fileOpen()'), actionCollection())
 
79
        KDE::StdAction.save(self, SLOT('fileSave()'), actionCollection())
 
80
        KDE::StdAction.saveAs(self, SLOT('fileSaveAs()'), actionCollection())
 
81
        KDE::StdAction.print(self, SLOT('filePrint()'), actionCollection())
 
82
        KDE::StdAction.quit($kapp, SLOT('quit()'), actionCollection())
 
83
    
 
84
        KDE::StdAction.preferences(self, SLOT('optionsPreferences()'), actionCollection())
 
85
    
 
86
        # this doesn't do anything useful.  it's just here to illustrate
 
87
        # how to insert a custom menu and menu item
 
88
        custom = KDE::Action.new(i18n("Cus&tom Menuitem"), KDE::Shortcut.new(),
 
89
                                    self, SLOT('optionsPreferences()'),
 
90
                                    actionCollection(), "custom_action")
 
91
    end
 
92
    
 
93
    def saveProperties(config)
 
94
        # the 'config' object points to the session managed
 
95
        # config file.  anything you write here will be available
 
96
        # later when this app is restored
 
97
    
 
98
        if !@view.currentURL().empty?
 
99
            config.writeEntry("lastURL", @view.currentURL())
 
100
        end
 
101
    end
 
102
    
 
103
    def readProperties(config)
 
104
        # the 'config' object points to the session managed
 
105
        # config file.  This function is automatically called whenever
 
106
        # the app is being restored.  read in here whatever you wrote
 
107
        # in 'saveProperties'
 
108
    
 
109
        url = config.readPathEntry("lastURL")
 
110
    
 
111
        if !url.empty?
 
112
            @view.openURL(KDE::URL.new(url))
 
113
        end
 
114
    end
 
115
    
 
116
    def dragEnterEvent(event)
 
117
        # accept uri drops only
 
118
        event.accept(KDE::URLDrag.canDecode(event))
 
119
    end
 
120
    
 
121
    def dropEvent(event)
 
122
        # This is a very simplistic implementation of a drop event.  we
 
123
        # will only accept a dropped URL.  the Qt dnd code can do *much*
 
124
        # much more, so please read the docs there
 
125
        urls = []
 
126
    
 
127
        # see if we can decode a URI.. if not, just ignore it
 
128
        if KDE::URLDrag.decode(event, urls) && !urls.empty?
 
129
            # okay, we have a URI.. process it
 
130
            url = urls.shift
 
131
    
 
132
            # load in the file
 
133
            load(url)
 
134
        end
 
135
    end
 
136
    
 
137
    def fileNew()
 
138
        # This slot is called whenever the File.New menu is selected,
 
139
        # the New shortcut is pressed (usually CTRL+N) or the New toolbar
 
140
        # button is clicked
 
141
    
 
142
        # create a new window
 
143
        %{APPNAMESC}.new.show()
 
144
    end
 
145
    
 
146
    def fileOpen()
 
147
        # This slot is called whenever the File.Open menu is selected,
 
148
        # the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
 
149
        # button is clicked
 
150
    
 
151
        # This brings up the generic open dialog
 
152
        url = KDE::URLRequesterDlg.getURL(nil, self, i18n("Open Location") )
 
153
    
 
154
        # standard filedialog
 
155
        url = KDE::FileDialog.getOpenURL(nil, nil, self, i18n("Open Location"))
 
156
        if !url.empty?
 
157
            @view.openURL(url)
 
158
        end
 
159
    end
 
160
    
 
161
    def fileSave()
 
162
        # This slot is called whenever the File.Save menu is selected,
 
163
        # the Save shortcut is pressed (usually CTRL+S) or the Save toolbar
 
164
        # button is clicked
 
165
    
 
166
        # save the current file
 
167
    end
 
168
    
 
169
    def fileSaveAs()
 
170
        # This slot is called whenever the File.Save As menu is selected,
 
171
        file_url = KDE::FileDialog.getSaveURL()
 
172
        if !file_url.empty? && file_url.valid?
 
173
            # save your info, here
 
174
        end
 
175
    end
 
176
    
 
177
    def filePrint()
 
178
        # This slot is called whenever the File.Print menu is selected,
 
179
        # the Print shortcut is pressed (usually CTRL+P) or the Print toolbar
 
180
        # button is clicked
 
181
        if @printer.nil? then @printer = KDE::Printer.new end
 
182
        if @printer.setup(self)
 
183
            # setup the printer.  with Qt, you always "print" to a
 
184
            # Qt::Painter.. whether the output medium is a pixmap, a screen,
 
185
            # or paper
 
186
            p = Qt::Painter.new
 
187
            p.begin(@printer)
 
188
    
 
189
            # we let our view do the actual printing
 
190
            metrics = Qt::PaintDeviceMetrics.new(@printer)
 
191
            @view.print(p, metrics.height(), metrics.width())
 
192
    
 
193
            # and send the result to the printer
 
194
            p.end()
 
195
        end
 
196
    end
 
197
        
 
198
    def optionsPreferences()
 
199
        # popup some sort of preference dialog, here
 
200
        dlg = %{APPNAMESC}Preferences.new
 
201
        if dlg.exec()
 
202
            # redo your settings
 
203
        end
 
204
    end
 
205
    
 
206
    def changeStatusbar(text)
 
207
        # display the text on the statusbar
 
208
        statusBar().message(text)
 
209
    end
 
210
    
 
211
    def changeCaption(text)
 
212
        # display the text on the caption
 
213
        setCaption(text)
 
214
    end
 
215
 
 
216
end