Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes
nsLicenseDlg Class Reference

#include <nsLicenseDlg.h>

Inheritance diagram for nsLicenseDlg:
Inheritance graph
[legend]
Collaboration diagram for nsLicenseDlg:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { SKIP_DIALOG = 0, SHOW_DIALOG = 1, FORWARD_MOVE = 555, BACKWARD_MOVE = -555 }
enum  { SKIP_DIALOG = 0, SHOW_DIALOG = 1 }

Public Member Functions

 nsLicenseDlg ()
 ~nsLicenseDlg ()
int Parse (nsINIParser *aParser)
int Show (int aDirection)
int Hide (int aDirection)
int SetLicenseFile (char *aLicenseFile)
char * GetLicenseFile ()
char * GetLicenseContents ()
 nsLicenseDlg ()
 ~nsLicenseDlg ()
int Parse (nsINIParser *aParser)
int Show ()
int Hide ()
int SetLicenseFile (char *aLicenseFile)
char * GetLicenseFile ()
char * GetLicenseContents ()
int SetShowDlg (int aShowDlg)
int SetShowDlg (int aShowDlg)
int GetShowDlg ()
int GetShowDlg ()
int SetTitle (char *aTitle)
int SetTitle (char *aTitle)
char * GetTitle ()
char * GetTitle ()
void SetPageNum (int aPageNum)
void SetPageNum (int aPageNum)
int GetPageNum ()
int GetPageNum ()

Static Public Member Functions

static void Back (GtkWidget *aWidget, gpointer aData)
static void Next (GtkWidget *aWidget, gpointer aData)
static void Back (GtkWidget *aWidget, gpointer aData)
static void Next (GtkWidget *aWidget, gpointer aData)

Protected Attributes

int mShowDlg
char * mTitle
char * mSubTitle
int mPageNum
int mWidgetsInit
GtkWidget * mTable

Private Attributes

char * mLicenseFile
char * mMsg0
char * mMsg1
GtkWidget * mBox

Detailed Description

Definition at line 46 of file nsLicenseDlg.h.


Member Enumeration Documentation

anonymous enum [inherited]
Enumerator:
SKIP_DIALOG 
SHOW_DIALOG 
FORWARD_MOVE 
BACKWARD_MOVE 

Definition at line 85 of file nsXInstallerDlg.h.

    {
        SKIP_DIALOG     = 0,
        SHOW_DIALOG     = 1,

        FORWARD_MOVE    = 555,
        BACKWARD_MOVE   = -555
    };
anonymous enum [inherited]
Enumerator:
SKIP_DIALOG 
SHOW_DIALOG 

Definition at line 85 of file nsXInstallerDlg.h.

    {
        SKIP_DIALOG     = 0,
        SHOW_DIALOG     = 1
    };

Constructor & Destructor Documentation

Definition at line 44 of file nsLicenseDlg.cpp.

Definition at line 50 of file nsLicenseDlg.cpp.


Member Function Documentation

void nsLicenseDlg::Back ( GtkWidget *  aWidget,
gpointer  aData 
) [static]

Definition at line 56 of file nsLicenseDlg.cpp.

{
    DUMP("Back");
    if (aData != gCtx->ldlg) return;
    
// XXX call gCtx->me->Shutdown() ?
    gtk_main_quit();
    return;

#if 0
    // hide this notebook page
    gCtx->ldlg->Hide(nsXInstallerDlg::BACKWARD_MOVE);

    // disconnect this dlg's nav btn signal handlers
    gtk_signal_disconnect(GTK_OBJECT(gCtx->back), gCtx->backID);
    gtk_signal_disconnect(GTK_OBJECT(gCtx->next), gCtx->nextID);

    // show the prev dlg
    gCtx->wdlg->Show(nsXInstallerDlg::BACKWARD_MOVE);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void nsLicenseDlg::Back ( GtkWidget *  aWidget,
gpointer  aData 
) [static]

Definition at line 284 of file nsLicenseDlg.cpp.

{
    char *buf = NULL;
    FILE *fd = NULL;
    struct stat attr;
    int buflen;

    DUMP(mLicenseFile);
    if (!mLicenseFile)
        return NULL;
   
    // open file
    fd = fopen(mLicenseFile, "r");
    if (!fd) return NULL;
    DUMP("license fopen");

    // get file length
    if (0 != stat(mLicenseFile, &attr)) return NULL;
    if (attr.st_size == 0) return NULL;
    DUMP("license fstat");

    // allocate buffer of file length
    buflen = sizeof(char) * (attr.st_size + 1);
    buf = (char *) malloc(buflen);
    if (!buf) return NULL;
    memset(buf, 0, buflen);
    DUMP("license buf malloc");

    // read entire file into buffer
    if (attr.st_size != ((int) fread(buf, sizeof(char), attr.st_size, fd))) 
        XI_IF_FREE(buf);
    DUMP("license fread");

    // close file
    fclose(fd);
    DUMP("license close");

    return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 275 of file nsLicenseDlg.cpp.

{
    if (mLicenseFile)
        return mLicenseFile;

    return NULL;
}

Definition at line 70 of file nsXInstallerDlg.cpp.

{
    return mShowDlg;
}
char * nsXInstallerDlg::GetTitle ( ) [inherited]

Definition at line 87 of file nsXInstallerDlg.cpp.

{
    if (mTitle)
        return mTitle;

    return NULL;
}
char* nsXInstallerDlg::GetTitle ( ) [inherited]
int nsLicenseDlg::Hide ( int  aDirection) [virtual]

Implements nsXInstallerDlg.

Definition at line 255 of file nsLicenseDlg.cpp.

{
    // hide all this dlg's widgets
  gtk_widget_hide(mBox);

    return OK;
}

Here is the caller graph for this function:

int nsLicenseDlg::Hide ( void  ) [virtual]

Implements nsXInstallerDlg.

Definition at line 241 of file nsLicenseDlg.cpp.

{
    // hide all this dlg's widgets
    gtk_widget_hide(mTable);

    // disconnect and remove this dlg's nav btns
    gtk_signal_disconnect(GTK_OBJECT(gCtx->back), gCtx->backID);
    gtk_signal_disconnect(GTK_OBJECT(gCtx->next), gCtx->nextID);

    gtk_container_remove(GTK_CONTAINER(gCtx->back), gCtx->declineLabel);
    gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->acceptLabel);

    gtk_widget_hide(gCtx->back);
    gtk_widget_hide(gCtx->next);
    
    return OK;
}
static void nsLicenseDlg::Next ( GtkWidget *  aWidget,
gpointer  aData 
) [static]
void nsLicenseDlg::Next ( GtkWidget *  aWidget,
gpointer  aData 
) [static]

Definition at line 79 of file nsLicenseDlg.cpp.

{
    DUMP("Next");
    if (aData != gCtx->ldlg) return;

    // hide this notebook page
    gCtx->ldlg->Hide(nsXInstallerDlg::FORWARD_MOVE);

    // disconnect this dlg's nav btn signal handlers
    gtk_signal_disconnect(GTK_OBJECT(gCtx->back), gCtx->backID);
    gtk_signal_disconnect(GTK_OBJECT(gCtx->next), gCtx->nextID);

    // show the next dlg
    gCtx->sdlg->Show(nsXInstallerDlg::FORWARD_MOVE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsLicenseDlg::Parse ( nsINIParser aParser) [virtual]

Implements nsXInstallerDlg.

int nsLicenseDlg::Parse ( nsINIParser aParser) [virtual]

Implements nsXInstallerDlg.

Definition at line 96 of file nsLicenseDlg.cpp.

{
    int err = OK;
    int bufsize = 0;
    char *showDlg = NULL;
    
    /* compulsory keys*/
    XI_ERR_BAIL(aParser->GetStringAlloc(DLG_LICENSE, LICENSE, 
                &mLicenseFile, &bufsize));
    if (bufsize == 0 || !mLicenseFile)
        return E_INVALID_KEY;

    bufsize = 5;
    XI_ERR_BAIL(aParser->GetStringAlloc(DLG_LICENSE, SHOW_DLG, &showDlg,
                                        &bufsize));
    if (bufsize != 0 && showDlg)
    {
        if (0 == strncmp(showDlg, "TRUE", 4))
            mShowDlg = nsXInstallerDlg::SHOW_DIALOG;
        else if (0 == strncmp(showDlg, "FALSE", 5))
            mShowDlg = nsXInstallerDlg::SKIP_DIALOG;
    }

    bufsize = 0;
    XI_ERR_BAIL(aParser->GetStringAlloc(DLG_LICENSE, TITLE, &mTitle,
                                        &bufsize));
    if (bufsize == 0)
            XI_IF_FREE(mTitle); 

    aParser->GetStringAlloc(DLG_LICENSE, SUBTITLE, &mSubTitle, &bufsize);
    if (bufsize == 0)
      XI_IF_FREE(mSubTitle);

    aParser->GetStringAlloc(DLG_LICENSE, MSG0, &mMsg0, &bufsize);
    if (bufsize == 0)
      XI_IF_FREE(mMsg0);

BAIL:
    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsLicenseDlg::SetLicenseFile ( char *  aLicenseFile)
int nsLicenseDlg::SetLicenseFile ( char *  aLicenseFile)

Definition at line 264 of file nsLicenseDlg.cpp.

{
    if (!aLicenseFile)
        return E_PARAM;

    mLicenseFile = aLicenseFile;

    return OK;
}
void nsXInstallerDlg::SetPageNum ( int  aPageNum) [inherited]
void nsXInstallerDlg::SetPageNum ( int  aPageNum) [inherited]
int nsXInstallerDlg::SetShowDlg ( int  aShowDlg) [inherited]

Definition at line 58 of file nsXInstallerDlg.cpp.

{
    if ( aShowDlg != nsXInstallerDlg::SHOW_DIALOG &&
         aShowDlg != nsXInstallerDlg::SKIP_DIALOG )
        return E_PARAM;

    mShowDlg = aShowDlg;

    return OK;
}
int nsXInstallerDlg::SetShowDlg ( int  aShowDlg) [inherited]
int nsXInstallerDlg::SetTitle ( char *  aTitle) [inherited]

Definition at line 76 of file nsXInstallerDlg.cpp.

{
    if (!aTitle)
        return E_PARAM;
    
    mTitle = aTitle;

    return OK;
}
int nsXInstallerDlg::SetTitle ( char *  aTitle) [inherited]
int nsLicenseDlg::Show ( void  ) [virtual]

Implements nsXInstallerDlg.

Definition at line 132 of file nsLicenseDlg.cpp.

{
    int err = OK;
    if (!mShowDlg)
    {
       gCtx->sdlg->Show();
       return err;
    }
    
    char *licenseContents = NULL;

    XI_VERIFY(gCtx);
    XI_VERIFY(gCtx->notebook);

    if (mWidgetsInit == FALSE) // static widget init
    {
        // create a new table and add it as a page of the notebook
        mTable = gtk_table_new(1, 3, FALSE);
        gtk_notebook_append_page(GTK_NOTEBOOK(gCtx->notebook), mTable, NULL);
        mPageNum = gtk_notebook_get_current_page(GTK_NOTEBOOK(gCtx->notebook));
        // gtk_table_set_row_spacing(GTK_TABLE(mTable), 0, 0);
        gtk_table_set_col_spacing(GTK_TABLE(mTable), 1, 0);
        gtk_widget_show(mTable);

        // read the license file contents into memory
        licenseContents = GetLicenseContents();
        if (!licenseContents)
        {
            err = ErrorHandler(E_EMPTY_LICENSE);
            goto BAIL;
        }

#if defined(MOZ_WIDGET_GTK)
        // create a new scrollable textarea and add it to the table
        GtkWidget *text = gtk_text_new(NULL, NULL);
        GdkFont *font = gdk_font_load( LICENSE_FONT );
        gtk_text_set_editable(GTK_TEXT(text), FALSE);
        gtk_text_set_word_wrap(GTK_TEXT(text), TRUE);
        gtk_text_set_line_wrap(GTK_TEXT(text), TRUE);
        gtk_table_attach(GTK_TABLE(mTable), text, 1, 2, 0, 1,
            static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND),
            static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND),
                     0, 0);
        gtk_text_freeze(GTK_TEXT(text));
        gtk_text_insert (GTK_TEXT(text), font, &text->style->black, NULL,
                          licenseContents, -1);
        gtk_text_thaw(GTK_TEXT(text));
        gtk_widget_show(text);

        // Add a vertical scrollbar to the GtkText widget 
        GtkWidget *vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
        gtk_table_attach(GTK_TABLE(mTable), vscrollbar, 2, 3, 0, 1,
            GTK_FILL,
                     static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_SHRINK | GTK_FILL),
                     0, 0);
        gtk_widget_show(vscrollbar);
#elif defined(MOZ_WIDGET_GTK2)
        GtkWidget *text = gtk_scrolled_window_new (NULL, NULL);
        GtkWidget *textview = gtk_text_view_new();
        GtkTextBuffer *textbuffer;

        textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
        gtk_text_buffer_set_text (textbuffer, licenseContents, -1);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (text),
            GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
        gtk_container_add (GTK_CONTAINER (text), textview);
        gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), FALSE);
        gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW(textview), FALSE);
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_WORD);
        gtk_table_attach(GTK_TABLE(mTable), text, 1, 2, 0, 1,
            static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND ),
            static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND), 0, 0);
        gtk_widget_show_all(text);
#endif

        mWidgetsInit = TRUE;
    }
    else
    {
        gtk_notebook_set_page(GTK_NOTEBOOK(gCtx->notebook), mPageNum);
        gtk_widget_show(mTable);
    }

    // signal connect the buttons
    gCtx->backID = gtk_signal_connect(GTK_OBJECT(gCtx->back), "clicked",
                   GTK_SIGNAL_FUNC(nsLicenseDlg::Back), gCtx->ldlg);
    gCtx->nextID = gtk_signal_connect(GTK_OBJECT(gCtx->next), "clicked",
                   GTK_SIGNAL_FUNC(nsLicenseDlg::Next), gCtx->ldlg);

    GTK_WIDGET_SET_FLAGS(gCtx->next, GTK_CAN_DEFAULT);
    gtk_widget_grab_default(gCtx->next);
    gtk_widget_grab_focus(gCtx->next);
    
    // always change the button titles to Accept/Decline
    gCtx->acceptLabel = gtk_label_new(gCtx->Res("ACCEPT"));
    gCtx->declineLabel = gtk_label_new(gCtx->Res("DECLINE"));
    gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->acceptLabel);
    gtk_container_add(GTK_CONTAINER(gCtx->back), gCtx->declineLabel);
    gtk_widget_show(gCtx->acceptLabel);
    gtk_widget_show(gCtx->declineLabel);
    gtk_widget_show(gCtx->next);
    gtk_widget_show(gCtx->back);

BAIL:
    XI_IF_FREE(licenseContents);
    return err;
}

Here is the call graph for this function:

int nsLicenseDlg::Show ( int  aDirection) [virtual]

Implements nsXInstallerDlg.

Definition at line 138 of file nsLicenseDlg.cpp.

{
    int err = OK;
    char *licenseContents = NULL;
    char *titleBuf;

    XI_VERIFY(gCtx);
    XI_VERIFY(gCtx->notebook);

    if (!mWidgetsInit) {
      // static widget init

      // Create a vbox with the message and scrolled window, and append it
      // as a page of the notebook.

      mBox = gtk_vbox_new(FALSE, 6);
      gtk_container_set_border_width(GTK_CONTAINER(mBox), 12);

      gtk_notebook_append_page(GTK_NOTEBOOK(gCtx->notebook), mBox, NULL);
      mPageNum = gtk_notebook_get_current_page(GTK_NOTEBOOK(gCtx->notebook));

      // Change "\n" in the label to a space and a literal newline character.
      char *newline = strstr(mMsg0, "\\n");
      if (newline) {
        newline[0] = ' ';
        newline[1] = '\n';
      }

      GtkWidget *msg0 = gtk_label_new(NULL);
      gtk_label_set_markup(GTK_LABEL(msg0), mMsg0);
      gtk_label_set_line_wrap(GTK_LABEL(msg0), TRUE);
      gtk_misc_set_alignment(GTK_MISC(msg0), 0.0, 0.5);
      gtk_box_pack_start(GTK_BOX(mBox), msg0, FALSE, FALSE, 0);

      GtkWidget *frame = gtk_frame_new(NULL);
      //      gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
      gtk_box_pack_start(GTK_BOX(mBox), frame, TRUE, TRUE, 0);

      GtkWidget *scrollWindow = gtk_scrolled_window_new(NULL, NULL);
      gtk_container_add(GTK_CONTAINER(frame), scrollWindow);

      // read the license file contents into memory
      licenseContents = GetLicenseContents();
      if (!licenseContents) {
        err = ErrorHandler(E_EMPTY_LICENSE);
        goto BAIL;
      }

      GtkTextBuffer *buffer = gtk_text_buffer_new(NULL);

      GtkTextIter start_iter;
      gtk_text_buffer_get_start_iter(buffer, &start_iter);
      gtk_text_buffer_insert_with_tags(buffer, &start_iter, licenseContents,
                                       -1, /* monoTag, */ NULL);

      GtkWidget *text = gtk_text_view_new_with_buffer(buffer);
      gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
      gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
      gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 2);
      gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 2);
      //      gtk_text_view_set_top_margin(GTK_TEXT_VIEW(text), 2);
      //      gtk_text_view_set_bottom_margin(GTK_TEXT_VIEW(text), 2);

      gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollWindow),
                                     GTK_POLICY_AUTOMATIC,
                                     GTK_POLICY_AUTOMATIC);

      gtk_container_add(GTK_CONTAINER(scrollWindow), text);

      mWidgetsInit = TRUE;
    } else {
      gtk_notebook_set_page(GTK_NOTEBOOK(gCtx->notebook), mPageNum);
    }

    gtk_widget_show_all(mBox);

    // <b>title</b>\0
    titleBuf = new char[strlen(mTitle) + 9];
    sprintf(titleBuf, "<b>%s</b>", mTitle);

    gtk_label_set_markup(GTK_LABEL(gCtx->header_title), titleBuf);
    gtk_label_set_text(GTK_LABEL(gCtx->header_subtitle), mSubTitle);

    delete[] titleBuf;

    // Set up the header if we're moving forward.
    if (aDirection == nsXInstallerDlg::FORWARD_MOVE) {
      GtkStyle *style = gtk_widget_get_style(gCtx->header);
      if (style->bg_pixmap[GTK_STATE_NORMAL]) {
        gint width, height;
        gdk_drawable_get_size(style->bg_pixmap[GTK_STATE_NORMAL],
                              &width, &height);
        gtk_widget_set_size_request(gCtx->header, -1, height);
      }
    }

    // signal connect the buttons
    gCtx->backID = gtk_signal_connect(GTK_OBJECT(gCtx->back), "clicked",
                   GTK_SIGNAL_FUNC(nsLicenseDlg::Back), gCtx->ldlg);
    gCtx->nextID = gtk_signal_connect(GTK_OBJECT(gCtx->next), "clicked",
                   GTK_SIGNAL_FUNC(nsLicenseDlg::Next), gCtx->ldlg);

    // enable back button if we came from the welcome dlg
    if (aDirection == nsXInstallerDlg::FORWARD_MOVE)
        if (gCtx->back)
            gtk_widget_set_sensitive(gCtx->back, TRUE); 

    // always change the button titles to Accept/Decline
    gtk_button_set_label(GTK_BUTTON(gCtx->next), gCtx->Res("ACCEPT"));
    gtk_button_set_label(GTK_BUTTON(gCtx->back), gCtx->Res("DECLINE"));

BAIL:
    XI_IF_FREE(licenseContents);
    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

GtkWidget* nsLicenseDlg::mBox [private]

Definition at line 74 of file nsLicenseDlg.h.

char * nsLicenseDlg::mLicenseFile [private]

Definition at line 71 of file nsLicenseDlg.h.

char* nsLicenseDlg::mMsg0 [private]

Definition at line 72 of file nsLicenseDlg.h.

char* nsLicenseDlg::mMsg1 [private]

Definition at line 73 of file nsLicenseDlg.h.

int nsXInstallerDlg::mPageNum [protected, inherited]

Definition at line 98 of file nsXInstallerDlg.h.

int nsXInstallerDlg::mShowDlg [protected, inherited]

Definition at line 95 of file nsXInstallerDlg.h.

char* nsXInstallerDlg::mSubTitle [protected, inherited]

Definition at line 97 of file nsXInstallerDlg.h.

GtkWidget * nsXInstallerDlg::mTable [protected, inherited]

Definition at line 100 of file nsXInstallerDlg.h.

char * nsXInstallerDlg::mTitle [protected, inherited]

Reimplemented in nsWelcomeDlg.

Definition at line 96 of file nsXInstallerDlg.h.

int nsXInstallerDlg::mWidgetsInit [protected, inherited]

Definition at line 99 of file nsXInstallerDlg.h.


The documentation for this class was generated from the following files: