[haiku-commits] r40216 - haiku/trunk/src/preferences/printers

Author: phoudoin
Date: 2011-01-12 18:08:35 +0100 (Wed, 12 Jan 2011)
New Revision: 40216
Changeset: http://dev.haiku-os.org/changeset/40216

Modified:
   haiku/trunk/src/preferences/printers/Messages.h
   haiku/trunk/src/preferences/printers/PrinterListView.h
   haiku/trunk/src/preferences/printers/PrintersWindow.cpp
   haiku/trunk/src/preferences/printers/PrintersWindow.h
Log:
WIP: add a print test page button.


Modified: haiku/trunk/src/preferences/printers/Messages.h
===================================================================
--- haiku/trunk/src/preferences/printers/Messages.h     2011-01-12 15:43:14 UTC 
(rev 40215)
+++ haiku/trunk/src/preferences/printers/Messages.h     2011-01-12 17:08:35 UTC 
(rev 40216)
@@ -21,5 +21,6 @@
 const uint32 kMsgCancelJob          = 'CncJ';
 const uint32 kMsgRestartJob         = 'RstJ';
 const uint32 kMsgJobSelected        = 'JSel';
+const uint32 kMsgPrintTestPage         = 'PtPg';
 
 #endif // _MESSAGES_H

Modified: haiku/trunk/src/preferences/printers/PrinterListView.h
===================================================================
--- haiku/trunk/src/preferences/printers/PrinterListView.h      2011-01-12 
15:43:14 UTC (rev 40215)
+++ haiku/trunk/src/preferences/printers/PrinterListView.h      2011-01-12 
17:08:35 UTC (rev 40216)
@@ -42,26 +42,26 @@
                        bool                            QuitRequested();
 
                        void                            BuildPrinterList();
-                       PrinterItem                     *SelectedItem() const;
-                       void                            UpdateItem(PrinterItem 
*item);
+                       PrinterItem*            SelectedItem() const;
+                       void                            UpdateItem(PrinterItem* 
item);
 
-                       PrinterItem             *ActivePrinter() const;
+                       PrinterItem*            ActivePrinter() const;
                        void                            
SetActivePrinter(PrinterItem* item);
 
 private:
                typedef BListView Inherited;
 
-                       void                            _AddPrinter(BDirectory 
&printer, bool calculateLayout);
+                       void                            _AddPrinter(BDirectory& 
printer, bool calculateLayout);
                        void                            _LayoutPrinterItems();
-                       PrinterItem                     *_FindItem(node_ref* 
node) const;
+                       PrinterItem*            _FindItem(node_ref* node) const;
 
-                       void                            EntryCreated(node_ref 
*node,
-                                                                       
entry_ref *entry);
-                       void                            EntryRemoved(node_ref 
*node);
-                       void                            
AttributeChanged(node_ref *node);
+                       void                            EntryCreated(node_ref* 
node,
+                                                                       
entry_ref* entry);
+                       void                            EntryRemoved(node_ref* 
node);
+                       void                            
AttributeChanged(node_ref* node);
 
-                       FolderWatcher           *fFolder;
-                       PrinterItem             *fActivePrinter;
+                       FolderWatcher*          fFolder;
+                       PrinterItem*            fActivePrinter;
                        PrinterListLayoutData   fLayoutData;
 };
 
@@ -76,25 +76,29 @@
                        void                            GetColumnWidth(BView* 
view, float& leftColumn,
                                                                        float& 
rightColumn);
 
-                       void                            DrawItem(BView *owner, 
BRect bounds,
+                       void                            DrawItem(BView* owner, 
BRect bounds,
                                                                        bool 
complete);
-                       void                            Update(BView *owner, 
const BFont *font);
+                       void                            Update(BView* owner, 
const BFont* font);
 
-                       bool                            Remove(BListView *view);
+                       bool                            Remove(BListView* view);
                        bool                            IsActivePrinter() const;
                        bool                            HasPendingJobs() const;
 
-                       const char                      *Name() const { return 
fName.String(); }
+                       const char*             Name() const { return 
fName.String(); }
+                       const char*                     Driver() const { return 
fDriverName.String(); }
+                       const char*                     Transport() const { 
return fTransport.String(); }
+                       const char*                     TransportAddress() const
+                                                                       { 
return fTransportAddress.String(); }
 
-                       SpoolFolder             *Folder() const;
-                       BDirectory                      *Node();
+                       SpoolFolder*            Folder() const;
+                       BDirectory*             Node();
                        void                            UpdatePendingJobs();
 
 private:
-                       void                            
_GetStringProperty(const char *propName,
-                                                                       BString 
&outString);
+                       void                            
_GetStringProperty(const char* propName,
+                                                                       
BString& outString);
 
-                       SpoolFolder                     *fFolder;
+                       SpoolFolder*            fFolder;
                        BDirectory                      fNode;
                        BString                         fComments;
                        BString                         fTransport;
@@ -104,8 +108,8 @@
                        BString                         fPendingJobs;
                        PrinterListLayoutData& fLayoutData;
 
-       static  BBitmap                         *sIcon;
-       static  BBitmap                         *sSelectedIcon;
+       static  BBitmap*                        sIcon;
+       static  BBitmap*                        sSelectedIcon;
 };
 
 #endif // _PRINTERS_LISTVIEW_H

Modified: haiku/trunk/src/preferences/printers/PrintersWindow.cpp
===================================================================
--- haiku/trunk/src/preferences/printers/PrintersWindow.cpp     2011-01-12 
15:43:14 UTC (rev 40215)
+++ haiku/trunk/src/preferences/printers/PrintersWindow.cpp     2011-01-12 
17:08:35 UTC (rev 40216)
@@ -1,14 +1,17 @@
 /*
- * Copyright 2001-2010, Haiku.
+ * Copyright 2001-2011, Haiku.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
  *             Michael Pfeiffer
+ *             Philippe Houdoin
  */
 
 
 #include "PrintersWindow.h"
 
+#include <stdio.h>
+
 // BeOS API
 #include <Application.h>
 #include <Button.h>
@@ -16,6 +19,7 @@
 #include <FindDirectory.h>
 #include <ListView.h>
 #include <Locale.h>
+#include <PrintJob.h>
 #include <ScrollView.h>
 
 #include "pr_server.h"
@@ -38,7 +42,7 @@
        fSelectedPrinter(NULL),
        fAddingPrinter(false)
 {
-       BuildGUI();
+       _BuildGUI();
 }
 
 
@@ -74,11 +78,11 @@
                                fSelectedPrinter = NULL;
                                fJobListView->SetSpoolFolder(NULL);
                        }
-                       UpdateJobButtons();
-                       UpdatePrinterButtons();
+                       _UpdateJobButtons();
+                       _UpdatePrinterButtons();
                        break;
                }
-               
+
                case kMsgAddPrinter:
                        if (!fAddingPrinter) {
                                fAddingPrinter = true;
@@ -97,7 +101,7 @@
                                fSelectedPrinter->Remove(fPrinterListView);
                        break;
                }
-               
+
                case kMsgMakeDefaultPrinter:
                {
                        PrinterItem* printer = fPrinterListView->SelectedItem();
@@ -109,11 +113,19 @@
                                setActivePrinter.AddSpecifier("ActivePrinter");
                                setActivePrinter.AddString("data", 
printer->Name());
                                msgr.SendMessage(&setActivePrinter);
-                               UpdatePrinterButtons();
+                               _UpdatePrinterButtons();
                        }
                        break;
                }
 
+               case kMsgPrintTestPage:
+               {
+                       fSelectedPrinter = fPrinterListView->SelectedItem();
+                       if (fSelectedPrinter)
+                               PrintTestPage(fSelectedPrinter);
+                       break;
+               }
+
                case kMsgCancelJob:
                        fJobListView->CancelJob();
                        break;
@@ -123,7 +135,7 @@
                        break;
 
                case kMsgJobSelected:
-                       UpdateJobButtons();
+                       _UpdateJobButtons();
                        break;
 
                case B_PRINTER_CHANGED:
@@ -151,8 +163,67 @@
 
 
 void
-PrintersWindow::BuildGUI()
+PrintersWindow::PrintTestPage(PrinterItem* printer)
 {
+       BPrintJob job("TestPage");
+       job.ConfigPage();
+       BMessage* settings = job.Settings();
+
+       printf("print job settings:\n");
+       settings->PrintToStream();
+
+       BRect pageRect = job.PrintableRect();
+
+       job.BeginJob();
+
+       // TestPageView testPage(pageRect, printer);
+       // job.DrawView(testPage, pageRect, BPoint(0.0, 0.0));
+       job.SpoolPage();
+       if (!job.CanContinue())
+               return;
+
+       job.CommitJob();
+}
+
+
+void
+PrintersWindow::AddJob(SpoolFolder* folder, Job* job)
+{
+       if (_IsSelected(folder->Item()))
+               fJobListView->AddJob(job);
+       fPrinterListView->UpdateItem(folder->Item());
+       _UpdatePrinterButtons();
+}
+
+
+void
+PrintersWindow::RemoveJob(SpoolFolder* folder, Job* job)
+{
+       if (_IsSelected(folder->Item()))
+               fJobListView->RemoveJob(job);
+       fPrinterListView->UpdateItem(folder->Item());
+       _UpdatePrinterButtons();
+}
+
+
+void
+PrintersWindow::UpdateJob(SpoolFolder* folder, Job* job)
+{
+       if (_IsSelected(folder->Item())) {
+               fJobListView->UpdateJob(job);
+               _UpdateJobButtons();
+       }
+       fPrinterListView->UpdateItem(folder->Item());
+       _UpdatePrinterButtons();
+}
+
+
+// #pragma mark -
+
+
+void
+PrintersWindow::_BuildGUI()
+{
        const float boxInset = 10.0;
        BRect r(Bounds());
 
@@ -163,7 +234,7 @@
        AddChild(backdrop);
 
 // ------------------------ Next, build the printers overview box
-       BBox* printersBox = new BBox(BRect(boxInset, boxInset, 
+       BBox* printersBox = new BBox(BRect(boxInset, boxInset,
                r.Width() - boxInset, (r.Height()/2) - (boxInset/2)),
                "printersBox", B_FOLLOW_ALL);
        printersBox->SetFont(be_bold_font);
@@ -201,6 +272,17 @@
        if (fMakeDefault->Bounds().Width() > maxWidth)
                maxWidth = fMakeDefault->Bounds().Width();
 
+               // Print Test Page button
+       fPrintTestPage = new BButton(BRect(5,60,5,60), "print_test_page",
+               B_TRANSLATE("Print test page"), new BMessage(kMsgPrintTestPage),
+               B_FOLLOW_RIGHT);
+       printersBox->AddChild(fPrintTestPage);
+       fPrintTestPage->ResizeToPreferred();
+
+       if (fPrintTestPage->Bounds().Width() > maxWidth)
+               maxWidth = fPrintTestPage->Bounds().Width();
+
+
                // Resize all buttons to maximum width and align them to the 
right
        float xPos = printersBox->Bounds().Width() - boxInset - maxWidth;
        addButton->MoveTo(xPos, boxInset + 8);
@@ -214,12 +296,19 @@
                boxInset + fRemove->Bounds().Height() + boxInset + 8);
        fMakeDefault->ResizeTo(maxWidth, fMakeDefault->Bounds().Height());
 
+       fPrintTestPage->MoveTo(xPos, boxInset + addButton->Bounds().Height() +
+               boxInset + fRemove->Bounds().Height() +
+               boxInset + fMakeDefault->Bounds().Height() + boxInset + 8);
+       fPrintTestPage->ResizeTo(maxWidth, fPrintTestPage->Bounds().Height());
+
+
                // Disable all selection-based buttons
        fRemove->SetEnabled(false);
        fMakeDefault->SetEnabled(false);
+       fPrintTestPage->SetEnabled(false);
 
                // Create listview with scroller
-       BRect listBounds(boxInset, boxInset + 8, 
+       BRect listBounds(boxInset, boxInset + 8,
                fMakeDefault->Frame().left - boxInset - B_V_SCROLL_BAR_WIDTH,
                printersBox->Bounds().Height()- boxInset - 3);
        fPrinterListView = new PrinterListView(listBounds);
@@ -229,7 +318,7 @@
 
 // ------------------------ Lastly, build the jobs overview box
        fJobsBox = new BBox(BRect(boxInset, r.Height() / 2 + boxInset / 2,
-               Bounds().Width() - 10, Bounds().Height() - boxInset), 
"jobsBox", 
+               Bounds().Width() - 10, Bounds().Height() - boxInset), "jobsBox",
                B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
        fJobsBox->SetFont(be_bold_font);
        fJobsBox->SetLabel(B_TRANSLATE("Print jobs: No printer selected"));
@@ -270,7 +359,7 @@
        restartButton->SetEnabled(false);
 
                // Create listview with scroller
-       listBounds = BRect(boxInset, boxInset + 8, 
+       listBounds = BRect(boxInset, boxInset + 8,
                cancelButton->Frame().left - boxInset - B_V_SCROLL_BAR_WIDTH,
                fJobsBox->Bounds().Height() - boxInset - 3);
        fJobListView = new JobListView(listBounds);
@@ -289,55 +378,24 @@
 
 
 bool
-PrintersWindow::IsSelected(PrinterItem* printer)
+PrintersWindow::_IsSelected(PrinterItem* printer)
 {
        return fSelectedPrinter && fSelectedPrinter == printer;
 }
 
 
 void
-PrintersWindow::AddJob(SpoolFolder* folder, Job* job)
+PrintersWindow::_UpdatePrinterButtons()
 {
-       if (IsSelected(folder->Item()))
-               fJobListView->AddJob(job);
-       fPrinterListView->UpdateItem(folder->Item());
-       UpdatePrinterButtons();
-}
-
-
-void
-PrintersWindow::RemoveJob(SpoolFolder* folder, Job* job)
-{
-       if (IsSelected(folder->Item()))
-               fJobListView->RemoveJob(job);
-       fPrinterListView->UpdateItem(folder->Item());
-       UpdatePrinterButtons();
-}
-
-
-void
-PrintersWindow::UpdateJob(SpoolFolder* folder, Job* job)
-{
-       if (IsSelected(folder->Item())) {
-               fJobListView->UpdateJob(job);
-               UpdateJobButtons();
-       }
-       fPrinterListView->UpdateItem(folder->Item());
-       UpdatePrinterButtons();
-}
-
-
-void
-PrintersWindow::UpdatePrinterButtons()
-{
        PrinterItem* item = fPrinterListView->SelectedItem();
        fRemove->SetEnabled(item && !item->HasPendingJobs());
        fMakeDefault->SetEnabled(item && !item->IsActivePrinter());
+       fPrintTestPage->SetEnabled(item);
 }
 
 
 void
-PrintersWindow::UpdateJobButtons()
+PrintersWindow::_UpdateJobButtons()
 {
        JobItem* item = fJobListView->SelectedItem();
        if (item != NULL) {
@@ -349,3 +407,5 @@
                fRestart->SetEnabled(false);
        }
 }
+
+

Modified: haiku/trunk/src/preferences/printers/PrintersWindow.h
===================================================================
--- haiku/trunk/src/preferences/printers/PrintersWindow.h       2011-01-12 
15:43:14 UTC (rev 40215)
+++ haiku/trunk/src/preferences/printers/PrintersWindow.h       2011-01-12 
17:08:35 UTC (rev 40216)
@@ -24,34 +24,37 @@
 class PrintersWindow : public BWindow {
 public:
        PrintersWindow(BRect frame);
-       
+
        void MessageReceived(BMessage* msg);
        bool QuitRequested();
-       
+
+       void PrintTestPage(PrinterItem* printer);
+
        void AddJob(SpoolFolder* folder, Job* job);
        void RemoveJob(SpoolFolder* folder, Job* job);
        void UpdateJob(SpoolFolder* folder, Job* job);
-       
+
 private:
-       void BuildGUI();
-       bool IsSelected(PrinterItem* printer);
-       void UpdatePrinterButtons();
-       void UpdateJobButtons();
+       void _BuildGUI();
+       bool _IsSelected(PrinterItem* printer);
+       void _UpdatePrinterButtons();
+       void _UpdateJobButtons();
 
        typedef BWindow Inherited;
-       
+
        PrinterListView*        fPrinterListView;
        BButton*        fMakeDefault;
        BButton*        fRemove;
+       BButton*        fPrintTestPage;
 
        JobListView*    fJobListView;
        BButton*        fRestart;
        BButton*    fCancel;
-       
+
        BBox*           fJobsBox;
 
        PrinterItem* fSelectedPrinter;
-       
+
        bool fAddingPrinter;
 };
 


Other related posts:

  • » [haiku-commits] r40216 - haiku/trunk/src/preferences/printers - philippe . houdoin