Back to index

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

#include <nsWelcomeDlg.h>

Inheritance diagram for nsWelcomeDlg:
Inheritance graph
[legend]
Collaboration diagram for nsWelcomeDlg:
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

 nsWelcomeDlg ()
 ~nsWelcomeDlg ()
int Parse (nsINIParser *aParser)
int Show (int aDirection)
int Hide (int aDirection)
 nsWelcomeDlg ()
 ~nsWelcomeDlg ()
int Parse (nsINIParser *aParser)
int Show ()
int Hide ()
int SetReadmeFile (char *aReadmeFile)
char * GetReadmeFile ()
char * GetReadmeContents ()
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 Next (GtkWidget *aWidget, gpointer aData)

Protected Attributes

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

Private Attributes

char * mTitle
char * mMsgs [kMsgCount]
char * mWelcomeMsg
char * mPixmap
GtkWidget * mBox
char * mReadmeFile

Static Private Attributes

static const int kMsgCount = 4

Detailed Description

Definition at line 46 of file nsWelcomeDlg.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 47 of file nsWelcomeDlg.cpp.

Here is the call graph for this function:

Definition at line 53 of file nsWelcomeDlg.cpp.


Member Function Documentation

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

Definition at line 64 of file nsWelcomeDlg.cpp.

{
  DUMP("Back");
  if (aData != gCtx->wdlg) return;
}

Here is the caller graph for this function:

Definition at line 252 of file nsWelcomeDlg.cpp.

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

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

    // get file length
    if (0 != stat(mReadmeFile, &attr)) return NULL;
    if (attr.st_size == 0) return NULL;
    DUMP("readme 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("readme 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("readme fread");

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

    return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 243 of file nsWelcomeDlg.cpp.

{
    if (mReadmeFile)
        return mReadmeFile;

    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 nsWelcomeDlg::Hide ( void  ) [virtual]

Implements nsXInstallerDlg.

Definition at line 218 of file nsWelcomeDlg.cpp.

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

    // disconnect and remove this dlg's nav btn
    gtk_signal_disconnect(GTK_OBJECT(gCtx->next), gCtx->nextID);
    gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->nextLabel);
    gtk_widget_hide(gCtx->next);

    return OK;
}
int nsWelcomeDlg::Hide ( int  aDirection) [virtual]

Implements nsXInstallerDlg.

Definition at line 275 of file nsWelcomeDlg.cpp.

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

  return OK;
}

Here is the caller graph for this function:

static void nsWelcomeDlg::Next ( GtkWidget *  aWidget,
gpointer  aData 
) [static]
void nsWelcomeDlg::Next ( GtkWidget *  aWidget,
gpointer  aData 
) [static]

Definition at line 71 of file nsWelcomeDlg.cpp.

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

  // hide this notebook page
  gCtx->wdlg->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->ldlg->Show(nsXInstallerDlg::FORWARD_MOVE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements nsXInstallerDlg.

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

Implements nsXInstallerDlg.

Definition at line 88 of file nsWelcomeDlg.cpp.

{
  int bufsize = 0;
  char *showDlg = NULL;
  char msgName[] = "Message0";
  char *tmp;

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

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

  bufsize = 0;
  aParser->GetStringAlloc(DLG_WELCOME, WATERMARK, &mPixmap, &bufsize);
  if (bufsize == 0)
    XI_IF_FREE(mPixmap);

  bufsize = 0;
  aParser->GetStringAlloc(DLG_WELCOME, MSGWELCOME, &tmp, &bufsize);
  if (bufsize == 0) {
    XI_IF_FREE(tmp);
  } else {
    mWelcomeMsg = g_strdup_printf(tmp, gCtx->opt->mProductName);
  }

  for (int i = 0; i < kMsgCount; ++i) {
    bufsize = 0;
    msgName[7] = (char)(i + 48);  // ASCII 48 == 0
    aParser->GetStringAlloc(DLG_WELCOME, msgName, &tmp, &bufsize);
    if (bufsize == 0) {
      XI_IF_FREE(tmp);
    } else {
      mMsgs[i] = g_strdup_printf(tmp, gCtx->opt->mProductName);
    }
  }

  return OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsXInstallerDlg::SetPageNum ( int  aPageNum) [inherited]
void nsXInstallerDlg::SetPageNum ( int  aPageNum) [inherited]
int nsWelcomeDlg::SetReadmeFile ( char *  aReadmeFile)

Definition at line 232 of file nsWelcomeDlg.cpp.

{
    if (!aReadmeFile)
        return E_PARAM;

    mReadmeFile = aReadmeFile;

    return OK;
}
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 nsWelcomeDlg::Show ( void  ) [virtual]

Implements nsXInstallerDlg.

Definition at line 117 of file nsWelcomeDlg.cpp.

{
    int err = OK;
    if (!mShowDlg)
    {
       gCtx->ldlg->Show();
       return err;
    }
   
    char *readmeContents = 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 readme file contents into memory
        readmeContents = GetReadmeContents();
        if (!readmeContents)
        {
            err = ErrorHandler(E_EMPTY_README);
            goto BAIL;
        }

        // create a new scrollable textarea and add it to the table
#if defined(MOZ_WIDGET_GTK)
        GtkWidget *text = gtk_text_new(NULL, NULL);
        GdkFont *font = gdk_font_load( README_FONT );
        gtk_text_set_editable(GTK_TEXT(text), FALSE);
        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,
                       readmeContents, -1);
        gtk_text_thaw(GTK_TEXT(text));
        gtk_text_set_word_wrap(GTK_TEXT(text), TRUE);
        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, readmeContents, -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_defaults(GTK_TABLE(mTable), text, 1, 2, 0, 1);
        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->nextID = gtk_signal_connect(GTK_OBJECT(gCtx->next), "clicked",
                   GTK_SIGNAL_FUNC(nsWelcomeDlg::Next), gCtx->wdlg);

    GTK_WIDGET_SET_FLAGS(gCtx->next, GTK_CAN_DEFAULT);
    gtk_widget_grab_default(gCtx->next);
    gtk_widget_grab_focus(gCtx->next);

    // show the Next button
    gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT"));
    gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel);
    gtk_widget_show(gCtx->nextLabel);
    gtk_widget_show(gCtx->next);

BAIL:
    XI_IF_FREE(readmeContents);

    return err;
}

Here is the call graph for this function:

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

Implements nsXInstallerDlg.

Definition at line 138 of file nsWelcomeDlg.cpp.

{
  int err = 0;
  int msgLength = 0;
  char *msgText, *textPos;

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

  if (mWidgetsInit == FALSE) {
    // static widget init

    // Note our page number in the wizard.
    mPageNum = gtk_notebook_get_current_page(GTK_NOTEBOOK(gCtx->notebook));

    // Set up the window title
    gtk_window_set_title(GTK_WINDOW(gCtx->window), mTitle);

    mBox = gtk_hbox_new(FALSE, 0);
    gtk_notebook_append_page(GTK_NOTEBOOK(gCtx->notebook), mBox, NULL);

    GtkWidget *wmbox = gtk_event_box_new();
    if (mPixmap) {
      GdkPixbuf *pb = gdk_pixbuf_new_from_file(mPixmap, NULL);
      if (pb) {
        GdkPixmap *pm = NULL;
        gdk_pixbuf_render_pixmap_and_mask(pb, &pm, NULL, 0);
        if (pm) {
          GtkStyle *newStyle = gtk_style_copy(gtk_widget_get_style(wmbox));
          newStyle->bg_pixmap[GTK_STATE_NORMAL] = pm;
          gtk_widget_set_style(wmbox, newStyle);

          // newStyle now owns the pixmap, so we don't unref it.
          g_object_unref(newStyle);

          // Make the watermark box the width of the pixmap.
          gint width, height;
          gdk_drawable_get_size(pm, &width, &height);
          gtk_widget_set_size_request(wmbox, width, -1);
        }

        // We're done with rendering the pixbuf, so we can destroy it.
        gdk_pixbuf_unref(pb);
      }
    }

    gtk_box_pack_start(GTK_BOX(mBox), wmbox, FALSE, FALSE, 0);

    wmbox = gtk_event_box_new();
    gtk_box_pack_start_defaults(GTK_BOX(mBox), wmbox);

    GtkWidget *inner_hbox = gtk_hbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(wmbox), inner_hbox);

    GtkWidget *spacer = gtk_alignment_new(0, 0, 0, 0);
    gtk_widget_set_size_request(spacer, 5, -1);
    gtk_box_pack_start(GTK_BOX(inner_hbox), spacer, FALSE, FALSE, 0);

    GtkWidget *vbox = gtk_vbox_new(FALSE, 8);
    gtk_box_pack_start(GTK_BOX(inner_hbox), vbox, FALSE, FALSE, 0);

    for (int i = 0; i < kMsgCount - 1; ++i)
      msgLength += strlen(mMsgs[i]);

#define kSpanBegin "<span weight=\"bold\" size=\"larger\">"
#define kSpanEnd   "</span>\n\n"

    msgLength += strlen(kSpanBegin) + strlen(mWelcomeMsg) + strlen(kSpanEnd);
    msgText = (char*) malloc(msgLength + (kMsgCount - 1) * 2 + 1);

    textPos = msgText;

    textPos += sprintf(textPos, kSpanBegin "%s" kSpanEnd, mWelcomeMsg);

    for (int i = 0; i < kMsgCount - 1; ++i)
      textPos += sprintf(textPos, "%s\n\n", mMsgs[i]);

    GtkWidget *msg = gtk_label_new(NULL);
    gtk_label_set_markup(GTK_LABEL(msg), msgText);
    gtk_label_set_line_wrap(GTK_LABEL(msg), TRUE);
    gtk_misc_set_alignment(GTK_MISC(msg), 0.0, 0.5);

    GdkColor black_col = { 0, 0, 0, 0 };
    GdkColor white_col = { 0, 65535, 65535, 65535 };

    gtk_widget_modify_text(msg, GTK_STATE_NORMAL, &black_col);
    gtk_widget_modify_bg(wmbox, GTK_STATE_NORMAL, &white_col);

    gtk_box_pack_start(GTK_BOX(vbox), msg, FALSE, FALSE, 0);
    gtk_container_child_set(GTK_CONTAINER(vbox), msg, "padding", 5, NULL);

    free(msgText);

    // Now add 100px of padding, and then the last mesage.
    spacer = gtk_alignment_new(0.0, 0.0, 0.0, 0.0);
    gtk_widget_set_size_request(spacer, -1, 110);
    gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0);

    msgText = (char*) malloc(strlen(mMsgs[kMsgCount - 1]) + 2);
    sprintf(msgText, "%s\n", mMsgs[kMsgCount - 1]);

    msg = gtk_label_new(msgText);
    gtk_widget_modify_text(msg, GTK_STATE_NORMAL, &black_col);
    gtk_misc_set_alignment(GTK_MISC(msg), 0.0, 0.5);
    gtk_box_pack_start(GTK_BOX(vbox), msg, FALSE, FALSE, 0);
    gtk_container_child_set(GTK_CONTAINER(vbox), msg, "padding", 5, NULL);

    free(msgText);

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

  // No header image for the welcome dialog
  gtk_widget_set_usize(gCtx->header, 0, 0);

  gtk_widget_show_all(mBox);

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

  gtk_widget_set_sensitive(gCtx->back, FALSE);

  GTK_WIDGET_SET_FLAGS(gCtx->next, GTK_CAN_DEFAULT);
  gtk_widget_grab_default(gCtx->next);
  gtk_widget_grab_focus(gCtx->next);

  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const int nsWelcomeDlg::kMsgCount = 4 [static, private]

Definition at line 68 of file nsWelcomeDlg.h.

GtkWidget* nsWelcomeDlg::mBox [private]

Definition at line 75 of file nsWelcomeDlg.h.

char* nsWelcomeDlg::mMsgs[kMsgCount] [private]

Definition at line 71 of file nsWelcomeDlg.h.

int nsXInstallerDlg::mPageNum [protected, inherited]

Definition at line 98 of file nsXInstallerDlg.h.

char* nsWelcomeDlg::mPixmap [private]

Definition at line 73 of file nsWelcomeDlg.h.

char* nsWelcomeDlg::mReadmeFile [private]

Definition at line 70 of file nsWelcomeDlg.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* nsWelcomeDlg::mTitle [private]

Reimplemented from nsXInstallerDlg.

Definition at line 70 of file nsWelcomeDlg.h.

char* nsWelcomeDlg::mWelcomeMsg [private]

Definition at line 72 of file nsWelcomeDlg.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: