Below is the beginnings of something I hope will grow into an example of 
URL/internalPath/pretty urls creation in wt. This is crucial for me (and 
others I'm sure) to understand to get SEO aspects correct in future 
developments. In an attempt to understand this better I have come up 
with the following code which I submit for review (be as harsh as you 
like :) ) As i said it's very rough and I guess I'm feeling it out to 
see if I have the general concept right and if this can evolve into a 
useful example.

One thing I would like to ask is when pathChange is called it appears to 
be called for each component of the path (a component being a string 
following a "/") in turn. How do I determine which is the final path, 
that is, pathChange will not be called again?

Anyway, here it is, any and all input is gratefully acknowledged.

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif


#include <Wt/WApplication>
#include <Wt/WPushButton>
#include <Wt/WMenu>
#include <Wt/WStackedWidget>
#include <Wt/WHBoxLayout>
#include <Wt/WContainerWidget>
#include <Wt/WText>
#include <Wt/WTextArea>
#include <Wt/WLogger>
#include <Wt/WAnchor>
#include <Wt/WBreak>

using namespace Wt;

class Test: public WApplication
{
public:
    Test( const WEnvironment& );
   
private:
    WMenu *m_mainMenu;
    WTextArea* m_textArea;
   
    WWidget* home();
    WWidget* option1();
    WWidget* option2();
    WWidget* option3();
    WWidget* option4();
    WWidget* option5();
   
private slots:
    void anchorClick();
    void anchorArgsClick();
    void pathChange( std::string prefix );
};

Test::Test( const WEnvironment& env ): WApplication( env )
{
   
    WHBoxLayout* hBox = new WHBoxLayout( root() );
   
    WContainerWidget* left_side = new WContainerWidget();
   
    left_side->addWidget( new WText( "****** Menu ******" ) );
   
    WStackedWidget* contents = new WStackedWidget();
    contents->setId( "main_page" );
   
    m_mainMenu = new WMenu( contents, Vertical, left_side );
    m_mainMenu->addItem( "home", home() )->setPathComponent("");
    m_mainMenu->addItem( "option1", option1() );
    m_mainMenu->addItem( "option2", option2() );
    m_mainMenu->addItem( "option3", option3() );
    m_mainMenu->addItem( "option4", option4() );
    m_mainMenu->addItem( "option5", option5() );
   
    // Make the menu internal-path aware.
    m_mainMenu->setInternalPathEnabled();
    m_mainMenu->setInternalBasePath( "/" );
    internalPathChanged.connect( SLOT( this, Test::pathChange ) );
    left_side->addWidget( contents );
   
    left_side->addWidget( new WBreak() );
    left_side->addWidget( new WText( "****** Anchors ******" ) );
    left_side->addWidget( new WBreak() );
   
    WAnchor *a1 = new WAnchor( left_side );
    a1->setRefInternalPath( "/anchor/" );
    a1->clicked.connect( SLOT( this, Test::anchorClick ) );
    new WText( "anchor", a1 );
   
    left_side->addWidget( new WBreak() );
   
    WAnchor *a2 = new WAnchor( left_side );
    a2->setRefInternalPath( "/anchor/blah/12346/test/" );
    a2->clicked.connect( SLOT( this, Test::anchorArgsClick ) );
    new WText( "anchor with arguments", a2 );
   
    left_side->addWidget( new WBreak() );
   
    WAnchor *a3 = new WAnchor( left_side );
    a3->setRefInternalPath( "/" );
    //a3->clicked.connect( SLOT( this, Test::anchorArgsClick ) );
    new WText( "anchor to menu option", a3 );
   
    left_side->addWidget( new WBreak() );
   
    WAnchor *a4 = new WAnchor( left_side );
    a4->setRefInternalPath( "/option4/blah/12346/test/" );
    //a3->clicked.connect( SLOT( this, Test::anchorArgsClick ) );
    new WText( "anchor to menu option with arguments", a4 );
   
    left_side->addWidget( new WBreak() );
   
    hBox->addWidget( left_side, 0, AlignLeft | AlignTop );
   
    m_textArea = new WTextArea();
    m_textArea->setColumns( 60 );
    m_textArea->setRows( 25 );
    hBox->addWidget( m_textArea, 0, AlignLeft | AlignTop );
   
}

void Test::anchorClick()
{
    m_textArea->setText( "Anchor Clicked" );
}

void Test::anchorArgsClick()
{
    WString text = "anchorArgsClick\n";
    //WString text = "Anchor with arguments Clicked\n";
    //text += "internal Path: " + internalPath();
    m_textArea->setText( text );
}

void Test::pathChange( std::string prefix )
{
    WString text = "pathChange\n";
    log("IpAth")<<internalPath();
    log("PrEfix") << prefix;
    log( "BoOkmark")<<bookmarkUrl();
    m_textArea->setText( text );
}

WWidget* Test::home()
{
    return new WText( "Home" );
}

WWidget* Test::option1()
{
    return new WText( "Option 1" );
}

WWidget* Test::option2()
{
    return new WText( "Option 2" );
}

WWidget* Test::option3()
{
    return new WText( "Option 3" );
}

WWidget* Test::option4()
{
    //log("O4:IpAth")<<internalPath();
    //log("O4:PrEfix") << prefix;
    //log( "O4:BoOkmark")<<bookmarkUrl();
    return new WText( "Option 4" );
}

WWidget* Test::option5()
{
    return new WText( "Option 5" );
}

WApplication *createApplication( const WEnvironment& env )
{
    return new Test( env );
}

int main( int argc, char **argv )
{
    return WRun( argc, argv, &createApplication );
}


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to