Changeset 231

Show
Ignore:
Timestamp:
06/13/06 15:16:36 (2 years ago)
Author:
jordi
Message:

Refactorized a little the printer options, so only one function adds data and one retrieved data.

Added the resolution list and also the setter function in the view.

Location:
trunk/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IPrintView.h

    r226 r231  
    8282            /// @param location The printer's location. 
    8383            /// 
    84             virtual void addPrinter (const gchar *name, int jobs, 
     84            virtual void addPrinter (const gchar *name, gint jobs, 
    8585                                     const gchar *state, 
    8686                                     const gchar *location) = 0; 
    8787 
    8888            /// 
     89            /// @brief Adds a new resolution to the list. 
     90            /// 
     91            /// @param name The possibly translated name of the resolution. 
     92            /// @param value The value the ePDFView internally uses to know 
     93            ///              which resolution is. 
     94            /// 
     95            virtual void addResolution (const gchar *name, 
     96                                        const gchar *value) = 0; 
     97 
     98            /// 
    8999            /// @brief Deletes all sizes from the list of page sizes. 
    90100            /// 
    91101            virtual void clearPageSizeList (void) = 0; 
     102 
     103            /// 
     104            /// @brief Deletes all resolutions from the list of resolutions. 
     105            /// 
     106            virtual void clearResolutionList (void) = 0; 
    92107 
    93108            /// 
     
    97112            ///         range is between 1 and 999. 
    98113            /// 
    99             virtual unsigned int getNumberOfCopies (void) = 0; 
     114            virtual guint getNumberOfCopies (void) = 0; 
    100115 
    101116            /// 
     
    173188            /// @brief Selects a page size. 
    174189            /// 
    175             /// @param pageSizeInde The index of the page size to select. 
     190            /// @param pageSizeIndex The index of the page size to select. 
    176191            /// 
    177192            virtual void selectPageSize (guint pageSizeIndex) = 0; 
     
    183198            /// 
    184199            virtual void selectPrinter (guint printerIndex) = 0; 
     200 
     201            /// 
     202            /// @brief Selects a page size. 
     203            /// 
     204            /// @param resolutionIndex The index of the resolution to select. 
     205            /// 
     206            virtual void selectResolution (guint resolutionIndex) = 0; 
    185207 
    186208            /// 
  • trunk/src/PrintPter.cxx

    r229 r231  
    212212                } 
    213213                view.selectPageSize (pageSizeToSelect); 
     214 
     215                // Get the resolutions. 
     216                ppd_option_t *resolutionOption = 
     217                    ppdFindOption (printerPPD, "Resolution"); 
     218                view.clearResolutionList (); 
     219                int resolutionToSelect = 0; 
     220                ppd_choice_t *resolutionChoice = resolutionOption->choices; 
     221                for ( int currentRes = 0 ; 
     222                      currentRes < resolutionOption->num_choices ; 
     223                      ++currentRes, ++resolutionChoice ) 
     224                { 
     225                    const gchar *resName = resolutionChoice->text; 
     226                    const gchar *resValue = resolutionChoice->choice; 
     227 
     228                    view.addResolution (_(resName), resValue); 
     229                    if ( resolutionChoice->marked ) 
     230                    { 
     231                        resolutionToSelect = currentRes; 
     232                    } 
     233                } 
     234                view.selectResolution (resolutionToSelect); 
    214235                ppdClose (printerPPD); 
    215236            } 
  • trunk/src/gtk/PrintView.cxx

    r230 r231  
    2525 
    2626// Enumerations. 
    27 static enum 
     27enum printerListColumns 
    2828{ 
    2929    printerListNameColumn, 
     
    3232    printerListLocationColumn, 
    3333    printerListNumColumn 
    34 } printerListColumns; 
    35  
    36 static enum 
    37 { 
    38     printOrientationLabelColumn, 
    39     printOrientationValueColumn, 
    40     printOrientationNumColumn 
    41 } printOritentationColumns; 
    42  
    43 static enum 
    44 { 
    45     printLayoutLabelColumn, 
    46     printLayoutValueColumn, 
    47     printLayoutNumColumn 
    48 } printLayoutColumns; 
    49  
    50 static enum 
    51 { 
    52     pageSizeNameColumn, 
    53     pageSizeValueColumn, 
    54     pageSizeNumColumn 
    55 } pageSizeColumns; 
     34}; 
     35 
     36enum printOptionsColumn 
     37{ 
     38    printOptionLabelColumn, 
     39    printOptionValueColumn, 
     40    printOptionNumColumn 
     41}; 
    5642 
    5743// Callbacks. 
     
    138124PrintView::addPageSize (const gchar *name, const gchar *value) 
    139125{ 
    140     GtkTreeIter pageSizeIter; 
    141     gtk_list_store_append (m_PageSize, &pageSizeIter); 
    142     gtk_list_store_set (m_PageSize, &pageSizeIter, 
    143                         pageSizeNameColumn, name, 
    144                         pageSizeValueColumn, value, 
    145                         -1); 
     126    addOptionToList (m_PageSize, name, value); 
    146127} 
    147128 
     
    161142 
    162143void 
     144PrintView::addResolution (const gchar *name, const gchar *value) 
     145{ 
     146    addOptionToList (m_Resolution, name, value); 
     147} 
     148 
     149void 
    163150PrintView::clearPageSizeList () 
    164151{ 
    165152    gtk_list_store_clear (m_PageSize); 
     153} 
     154 
     155void 
     156PrintView::clearResolutionList () 
     157{ 
     158    gtk_list_store_clear (m_Resolution); 
    166159} 
    167160 
     
    176169{ 
    177170    PrintPageLayout layout = PRINT_PAGE_LAYOUT_PLAIN; 
    178     GtkTreeIter layoutIter; 
    179     if ( gtk_combo_box_get_active_iter (GTK_COMBO_BOX (m_LayoutView), 
    180                                         &layoutIter) ) 
    181     { 
    182         gtk_tree_model_get (GTK_TREE_MODEL (m_Layout), &layoutIter, 
    183                             printLayoutValueColumn, &layout, 
    184                             -1); 
    185     } 
    186  
     171    getOptionFromComboBox (m_LayoutView, &layout); 
    187172    return layout; 
    188173} 
     
    192177{ 
    193178    PrintPageOrientation orientation = PRINT_PAGE_ORIENTATION_PORTRAIT; 
    194     GtkTreeIter orientationIter; 
    195     if ( gtk_combo_box_get_active_iter (GTK_COMBO_BOX (m_OrientationView), 
    196                                         &orientationIter) ) 
    197     { 
    198         gtk_tree_model_get (GTK_TREE_MODEL (m_Orientation), &orientationIter, 
    199                             printOrientationValueColumn, &orientation, 
    200                             -1); 
    201     } 
     179    getOptionFromComboBox (m_OrientationView, &orientation); 
    202180    return orientation; 
    203181} 
     
    213191{ 
    214192    gchar *pageSize = NULL; 
    215     GtkTreeIter pageSizeIter; 
    216     if ( gtk_combo_box_get_active_iter (GTK_COMBO_BOX (m_PageSizeView), 
    217                                         &pageSizeIter) ) 
    218     { 
    219         gtk_tree_model_get (GTK_TREE_MODEL (m_PageSize), &pageSizeIter, 
    220                             pageSizeValueColumn, &pageSize, 
    221                             -1); 
    222     } 
     193    getOptionFromComboBox (m_PageSizeView, &pageSize); 
    223194    return pageSize; 
    224195} 
     
    268239 
    269240void 
    270 PrintView::selectPageSize (unsigned int pageSizeIndex) 
     241PrintView::selectPageSize (guint pageSizeIndex) 
    271242{ 
    272243    gtk_combo_box_set_active (GTK_COMBO_BOX (m_PageSizeView), pageSizeIndex); 
     
    274245 
    275246void 
    276 PrintView::selectPrinter (unsigned int printerIndex) 
     247PrintView::selectPrinter (guint printerIndex) 
    277248{ 
    278249    gchar *pathString = g_strdup_printf ("%d", printerIndex); 
     
    289260 
    290261void 
     262PrintView::selectResolution (guint resolutionIndex) 
     263{ 
     264    gtk_combo_box_set_active (GTK_COMBO_BOX (m_ResolutionView), 
     265                              resolutionIndex); 
     266} 
     267 
     268void 
    291269PrintView::sensitiveCollate (gboolean sensitive) 
    292270{ 
     
    305283    gtk_dialog_set_response_sensitive (GTK_DIALOG (m_PrintDialog), 
    306284                                       GTK_RESPONSE_ACCEPT, sensitive); 
     285} 
     286 
     287void 
     288PrintView::addOptionToList (GtkListStore *optionList, const gchar *name, 
     289                            const gchar *value) 
     290{ 
     291    GtkTreeIter newOptionIter; 
     292    gtk_list_store_append (optionList, &newOptionIter); 
     293    gtk_list_store_set (optionList, &newOptionIter, 
     294                        printOptionLabelColumn, name, 
     295                        printOptionValueColumn, value, 
     296                        -1); 
     297} 
     298 
     299void 
     300PrintView::getOptionFromComboBox (GtkWidget *comboBox, gpointer value) 
     301{ 
     302    GtkTreeIter optionIter; 
     303    if ( gtk_combo_box_get_active_iter (GTK_COMBO_BOX (comboBox), &optionIter) ) 
     304    { 
     305        GtkTreeModel *model = 
     306            gtk_combo_box_get_model (GTK_COMBO_BOX (comboBox)); 
     307        gtk_tree_model_get (model, &optionIter, 
     308                            printOptionValueColumn, value, 
     309                            -1); 
     310    } 
    307311} 
    308312 
     
    454458                                        renderer, 
    455459                                        "text", 
    456                                         printOrientationLabelColumn, NULL); 
     460                                        printOptionLabelColumn, NULL); 
    457461    } 
    458462    gtk_table_attach (GTK_TABLE (paperTable), paperSizeLabel, 
     
    483487                                        renderer, 
    484488                                        "text", 
    485                                         printOrientationLabelColumn, NULL); 
     489                                        printOptionLabelColumn, NULL); 
    486490    } 
    487491    gtk_combo_box_set_active (GTK_COMBO_BOX (m_OrientationView), 0); 
     
    511515        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (m_LayoutView), 
    512516                                        renderer, 
    513                                         "text", printLayoutLabelColumn, NULL); 
     517                                        "text", printOptionLabelColumn, NULL); 
    514518    } 
    515519    gtk_combo_box_set_active (GTK_COMBO_BOX (m_LayoutView), 0); 
     
    557561                                        renderer, 
    558562                                        "text", 
    559                                         // XXX: Change with the final column 
    560                                         0, NULL); 
     563                                        printOptionLabelColumn, NULL); 
    561564    } 
    562565    gtk_table_attach (GTK_TABLE (outputTable), colorModeLabel, 
     
    575578    gtk_label_set_use_underline (GTK_LABEL (resolutionLabel), TRUE); 
    576579 
    577 //    createResolutionListModel (); 
    578     GtkWidget *resolutionView = gtk_combo_box_new (); //_with_model (GTK_TREE_MODEL (m_Resolution)); 
     580    createResolutionListModel (); 
     581    m_ResolutionView = 
     582        gtk_combo_box_new_with_model (GTK_TREE_MODEL (m_Resolution)); 
    579583    gtk_label_set_mnemonic_widget (GTK_LABEL (resolutionLabel), 
    580                                    resolutionView); 
    581     { 
    582         GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); 
    583         gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (resolutionView), 
     584                                   m_ResolutionView); 
     585    { 
     586        GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); 
     587        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (m_ResolutionView), 
    584588                                    renderer, TRUE); 
    585         gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (resolutionView), 
     589        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (m_ResolutionView), 
    586590                                        renderer, 
    587591                                        "text", 
    588                                         // XXX Change with the final column 
    589                                         0, NULL); 
     592                                        printOptionLabelColumn, NULL); 
    590593    } 
    591594    gtk_table_attach (GTK_TABLE (outputTable), resolutionLabel, 
     
    594597                      (GtkAttachOptions)(GTK_SHRINK), 
    595598                      0, 0); 
    596     gtk_table_attach (GTK_TABLE (outputTable), resolutionView, 
     599    gtk_table_attach (GTK_TABLE (outputTable), m_ResolutionView, 
    597600                      1, 2, 1, 2, 
    598601                      (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
     
    660663PrintView::createLayoutListModel () 
    661664{ 
    662     m_Layout = gtk_list_store_new (printLayoutNumColumn, 
     665    m_Layout = gtk_list_store_new (printOptionNumColumn, 
    663666                                   G_TYPE_STRING,  // Label 
    664667                                   G_TYPE_INT);    // Value 
     
    667670    gtk_list_store_append (m_Layout, &iter); 
    668671    gtk_list_store_set (m_Layout, &iter, 
    669                         printLayoutLabelColumn, _("Plain"), 
    670                         printLayoutValueColumn, PRINT_PAGE_LAYOUT_PLAIN, 
     672                        printOptionLabelColumn, _("Plain"), 
     673                        printOptionValueColumn, PRINT_PAGE_LAYOUT_PLAIN, 
    671674                        -1); 
    672675 
    673676    gtk_list_store_append (m_Layout, &iter); 
    674677    gtk_list_store_set (m_Layout, &iter, 
    675                         printLayoutLabelColumn, _("2 pages in 1"), 
    676                         printLayoutValueColumn, PRINT_PAGE_LAYOUT_2IN1, 
     678                        printOptionLabelColumn, _("2 pages in 1"), 
     679                        printOptionValueColumn, PRINT_PAGE_LAYOUT_2IN1, 
    677680                        -1); 
    678681 
    679682    gtk_list_store_append (m_Layout, &iter); 
    680683    gtk_list_store_set (m_Layout, &iter, 
    681                         printLayoutLabelColumn, _("4 pages in 1"), 
    682                         printLayoutValueColumn, PRINT_PAGE_LAYOUT_4IN1, 
     684                        printOptionLabelColumn, _("4 pages in 1"), 
     685                        printOptionValueColumn, PRINT_PAGE_LAYOUT_4IN1, 
    683686                        -1); 
    684687} 
     
    687690PrintView::createOrientationListModel () 
    688691{ 
    689     m_Orientation = gtk_list_store_new (printOrientationNumColumn, 
     692    m_Orientation = gtk_list_store_new (printOptionNumColumn, 
    690693                                        G_TYPE_STRING,  // Label 
    691694                                        G_TYPE_INT);    // Value 
     
    694697    gtk_list_store_append (m_Orientation, &iter); 
    695698    gtk_list_store_set (m_Orientation, &iter, 
    696                 printOrientationLabelColumn, _("Portrait"), 
    697                 printOrientationValueColumn, PRINT_PAGE_ORIENTATION_PORTRAIT, 
     699                printOptionLabelColumn, _("Portrait"), 
     700                printOptionValueColumn, PRINT_PAGE_ORIENTATION_PORTRAIT, 
    698701                -1); 
    699702 
    700703    gtk_list_store_append (m_Orientation, &iter); 
    701704    gtk_list_store_set (m_Orientation, &iter, 
    702                 printLayoutLabelColumn, _("Landscape"), 
    703                 printOrientationValueColumn, PRINT_PAGE_ORIENTATION_LANDSCAPE, 
     705                printOptionLabelColumn, _("Landscape"), 
     706                printOptionValueColumn, PRINT_PAGE_ORIENTATION_LANDSCAPE, 
    704707                -1); 
    705708} 
     
    708711PrintView::createPageSizeListModel () 
    709712{ 
    710     m_PageSize = gtk_list_store_new (pageSizeNumColumn, 
     713    m_PageSize = gtk_list_store_new (printOptionNumColumn, 
    711714                                     G_TYPE_STRING,  // Label 
    712715                                     G_TYPE_STRING); // Value 
     
    725728} 
    726729 
     730void 
     731PrintView::createResolutionListModel () 
     732{ 
     733    m_Resolution = gtk_list_store_new (printOptionNumColumn, 
     734                                       G_TYPE_STRING,  // Label 
     735                                       G_TYPE_STRING); // Value 
     736} 
     737 
     738 
     739 
    727740//////////////////////////////////////////////////////////////// 
    728741// Callbacks 
  • trunk/src/gtk/PrintView.h

    r222 r231  
    3131            virtual void addPageSize (const gchar *name, 
    3232                                      const gchar *value); 
    33             virtual void addPrinter (const gchar *name, int jobs, 
     33            virtual void addPrinter (const gchar *name, gint jobs, 
    3434                                     const gchar *state, 
    3535                                     const gchar *location); 
     36            virtual void addResolution (const gchar *name, 
     37                                        const gchar *value); 
    3638            virtual void clearPageSizeList (void); 
    37             virtual unsigned int getNumberOfCopies (void); 
     39            virtual void clearResolutionList (void); 
     40            virtual guint getNumberOfCopies (void); 
    3841            virtual PrintPageLayout getPageLayout (void); 
    3942            virtual PrintPageOrientation getPageOrientation (void); 
     
    4548            virtual gboolean isSelectedEvenPageSet (void); 
    4649            virtual gboolean isSelectedOddPageSet (void); 
    47             virtual void selectPageSize (unsigned int pageSizeIndex); 
    48             virtual void selectPrinter (unsigned int printerIndex); 
     50            virtual void selectPageSize (guint pageSizeIndex); 
     51            virtual void selectPrinter (guint printerIndex); 
     52            virtual void selectResolution (guint resolutionIndex); 
    4953            virtual void sensitiveCollate (gboolean sensitive); 
    5054            virtual void sensitivePageRange (gboolean sensitive); 
     
    6872            GtkListStore *m_PrinterList; 
    6973            GtkWidget *m_PrinterListView; 
     74            GtkListStore *m_Resolution; 
     75            GtkWidget *m_ResolutionView; 
     76 
     77            void addOptionToList (GtkListStore *optionList, 
     78                                  const gchar *name, const gchar *value); 
     79            void getOptionFromComboBox (GtkWidget *comboBox, gpointer value); 
    7080 
    7181            GtkWidget *createJobTab (void); 
     
    7787            void createPageSizeListModel (void); 
    7888            void createPrinterListModel (void); 
     89            void createResolutionListModel (void); 
    7990    }; 
    8091}