summaryrefslogtreecommitdiffstats
path: root/korundum/rubylib/tutorials/p9/p9.rb
blob: 48a01fdc1efe786db9bd741c2f9e9ada0492f4d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
retquire 'Korundum'
    
class Browser < KDE::MainWindow
    k_dcop  'void setURL(TQString)'
	
	slots   'fileSetDefaultPage()', 
            'changeLocation()',
            'bookLocation()',
            'gotoPreviousPage()',
            'openURLRequest(const KURL&, const KParts::URLArgs&)'
 
    def initialize( name )
        super(nil, name)
        @history = []

        KDE::StdAction.quit(self, SLOT('close()'), actionCollection())

        KDE::Action.new(i18n("&Set default page"), "gohome", KDE::Shortcut.new(0), self,
		    SLOT('fileSetDefaultPage()'), actionCollection(), "set_default_page")

        KDE::Action.new(i18n("Add to Bookmarks"), "reload", KDE::Shortcut.new(0), self,
		    SLOT('bookLocation()'), actionCollection(), "add_to_bookmarks")

        KDE::Action.new(i18n("Back to previous page"), "back", KDE::Shortcut.new(0), self,
		    SLOT('gotoPreviousPage()'), actionCollection(), "back")

        actionCollection().action("back").setEnabled(false)

        createGUI(Dir.getwd + "/p9ui.rc")

        vbox = TQt::VBox.new( self )
 
        @location = TQt::LineEdit.new( vbox )

        config = $kapp.config()
        config.setGroup("Settings")
        @location.text = config.readEntry( "defaultPage", "http://localhost")

        connect( @location , SIGNAL( 'returnPressed()' ),
                    self, SLOT( 'changeLocation()' ) )

		@browser = KDE::HTMLPart.new( vbox )
        @browser.openURL( KDE::URL.new(@location.text()) )

        connect( @browser.browserExtension(),
	            SIGNAL( 'openURLRequest( const KURL&, const KParts::URLArgs& )' ),
	            self, SLOT( 'openURLRequest(const KURL&, const KParts::URLArgs& )' ) )           	     
        setCentralWidget(vbox)
    end


    def changeLocation()
        @history.push( @browser.url().url() );
        actionCollection().action("back").setEnabled(true)
        @browser.openURL( KDE::URL.new(@location.text()) )
    end

    def setURL( url )
        @location.text = url
        changeLocation()
    end

    def openURLRequest(url, part)
        setURL( url.url() )
    end

    def gotoPreviousPage()
        @location.text = @history.pop() 
        if @history.empty?
            actionCollection().action("back").setEnabled(false)
        end
        @browser.openURL( KDE::URL.new(@location.text()) )
    end

    def bookLocation()
        dcopRef = KDE::DCOPRef.new("p8", "BookMarkList")
        if ! dcopRef.add(@location.text())
            qWarning("Error with DCOP\n")
        end
    end

    def fileSetDefaultPage()
        config = $kapp.config()
 
        config.group = "Settings"
        config.writeEntry( "defaultPage", @browser.url().url() )
    end
end

	aboutdata = KDE::AboutData.new("p9", "Tutorial - p9",
      "1.0", "Step 9 of a simple tutorial", KDE::AboutData::License_GPL,
      "(C) 2000, 2001 Antonio Larrosa Jimenez","",
      "http://devel-home.kde.org/~larrosa/tutorial.html")
    aboutdata.addAuthor("Antonio Larrosa Jimenez",
      "Original Developer/Mantainer","larrosa@kde.org",
      "http://devel-home.kde.org/~larrosa/index.html")
    aboutdata.addAuthor("Richard Dale",
      "Ruby port","Richard_Dale@tipitina.demon.co.uk",
      "")    
	KDE::CmdLineArgs.init(ARGV, aboutdata)
	
    a = KDE::UniqueApplication.new()
	
    window = Browser.new( "Tutorial - p9" )
    window.resize( 300, 200 )
	
    a.mainWidget = window
    window.show
	
    a.exec