network_content_gui.cpp

Go to the documentation of this file.
00001 /* $Id: network_content_gui.cpp 26167 2013-12-20 18:29:53Z frosch $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #if defined(ENABLE_NETWORK)
00013 #include "../stdafx.h"
00014 #include "../strings_func.h"
00015 #include "../gfx_func.h"
00016 #include "../window_func.h"
00017 #include "../error.h"
00018 #include "../ai/ai.hpp"
00019 #include "../game/game.hpp"
00020 #include "../base_media_base.h"
00021 #include "../sortlist_type.h"
00022 #include "../stringfilter_type.h"
00023 #include "../querystring_gui.h"
00024 #include "../core/geometry_func.hpp"
00025 #include "../textfile_gui.h"
00026 #include "network_content_gui.h"
00027 
00028 
00029 #include "table/strings.h"
00030 #include "../table/sprites.h"
00031 
00032 
00034 static bool _accepted_external_search = false;
00035 
00036 
00038 struct ContentTextfileWindow : public TextfileWindow {
00039   const ContentInfo *ci; 
00040 
00041   ContentTextfileWindow(TextfileType file_type, const ContentInfo *ci) : TextfileWindow(file_type), ci(ci)
00042   {
00043     const char *textfile = this->ci->GetTextfile(file_type);
00044     this->LoadTextfile(textfile, GetContentInfoSubDir(this->ci->type));
00045   }
00046 
00047   StringID GetTypeString() const
00048   {
00049     switch (this->ci->type) {
00050       case CONTENT_TYPE_NEWGRF:        return STR_CONTENT_TYPE_NEWGRF;
00051       case CONTENT_TYPE_BASE_GRAPHICS: return STR_CONTENT_TYPE_BASE_GRAPHICS;
00052       case CONTENT_TYPE_BASE_SOUNDS:   return STR_CONTENT_TYPE_BASE_SOUNDS;
00053       case CONTENT_TYPE_BASE_MUSIC:    return STR_CONTENT_TYPE_BASE_MUSIC;
00054       case CONTENT_TYPE_AI:            return STR_CONTENT_TYPE_AI;
00055       case CONTENT_TYPE_AI_LIBRARY:    return STR_CONTENT_TYPE_AI_LIBRARY;
00056       case CONTENT_TYPE_GAME:          return STR_CONTENT_TYPE_GAME_SCRIPT;
00057       case CONTENT_TYPE_GAME_LIBRARY:  return STR_CONTENT_TYPE_GS_LIBRARY;
00058       case CONTENT_TYPE_SCENARIO:      return STR_CONTENT_TYPE_SCENARIO;
00059       case CONTENT_TYPE_HEIGHTMAP:     return STR_CONTENT_TYPE_HEIGHTMAP;
00060       default: NOT_REACHED();
00061     }
00062   }
00063 
00064   /* virtual */ void SetStringParameters(int widget) const
00065   {
00066     if (widget == WID_TF_CAPTION) {
00067       SetDParam(0, this->GetTypeString());
00068       SetDParamStr(1, this->ci->name);
00069     }
00070   }
00071 };
00072 
00073 void ShowContentTextfileWindow(TextfileType file_type, const ContentInfo *ci)
00074 {
00075   DeleteWindowByClass(WC_TEXTFILE);
00076   new ContentTextfileWindow(file_type, ci);
00077 }
00078 
00080 static const NWidgetPart _nested_network_content_download_status_window_widgets[] = {
00081   NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CONTENT_DOWNLOAD_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00082   NWidget(WWT_PANEL, COLOUR_GREY, WID_NCDS_BACKGROUND),
00083     NWidget(NWID_SPACER), SetMinimalSize(350, 0), SetMinimalTextLines(3, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 30),
00084     NWidget(NWID_HORIZONTAL),
00085       NWidget(NWID_SPACER), SetMinimalSize(125, 0),
00086       NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCDS_CANCELOK), SetMinimalSize(101, 12), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
00087       NWidget(NWID_SPACER), SetFill(1, 0),
00088     EndContainer(),
00089     NWidget(NWID_SPACER), SetMinimalSize(0, 4),
00090   EndContainer(),
00091 };
00092 
00094 static WindowDesc _network_content_download_status_window_desc(
00095   WDP_CENTER, NULL, 0, 0,
00096   WC_NETWORK_STATUS_WINDOW, WC_NONE,
00097   WDF_MODAL,
00098   _nested_network_content_download_status_window_widgets, lengthof(_nested_network_content_download_status_window_widgets)
00099 );
00100 
00101 BaseNetworkContentDownloadStatusWindow::BaseNetworkContentDownloadStatusWindow(WindowDesc *desc) :
00102     Window(desc), cur_id(UINT32_MAX)
00103 {
00104   _network_content_client.AddCallback(this);
00105   _network_content_client.DownloadSelectedContent(this->total_files, this->total_bytes);
00106 
00107   this->InitNested(WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD);
00108 }
00109 
00110 BaseNetworkContentDownloadStatusWindow::~BaseNetworkContentDownloadStatusWindow()
00111 {
00112   _network_content_client.RemoveCallback(this);
00113 }
00114 
00115 /* virtual */ void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, int widget) const
00116 {
00117   if (widget != WID_NCDS_BACKGROUND) return;
00118 
00119   /* Draw nice progress bar :) */
00120   DrawFrameRect(r.left + 20, r.top + 4, r.left + 20 + (int)((this->width - 40LL) * this->downloaded_bytes / this->total_bytes), r.top + 14, COLOUR_MAUVE, FR_NONE);
00121 
00122   int y = r.top + 20;
00123   SetDParam(0, this->downloaded_bytes);
00124   SetDParam(1, this->total_bytes);
00125   SetDParam(2, this->downloaded_bytes * 100LL / this->total_bytes);
00126   DrawString(r.left + 2, r.right - 2, y, STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, TC_FROMSTRING, SA_HOR_CENTER);
00127 
00128   StringID str;
00129   if (this->downloaded_bytes == this->total_bytes) {
00130     str = STR_CONTENT_DOWNLOAD_COMPLETE;
00131   } else if (!StrEmpty(this->name)) {
00132     SetDParamStr(0, this->name);
00133     SetDParam(1, this->downloaded_files);
00134     SetDParam(2, this->total_files);
00135     str = STR_CONTENT_DOWNLOAD_FILE;
00136   } else {
00137     str = STR_CONTENT_DOWNLOAD_INITIALISE;
00138   }
00139 
00140   y += FONT_HEIGHT_NORMAL + 5;
00141   DrawStringMultiLine(r.left + 2, r.right - 2, y, y + FONT_HEIGHT_NORMAL * 2, str, TC_FROMSTRING, SA_CENTER);
00142 }
00143 
00144 /* virtual */ void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInfo *ci, int bytes)
00145 {
00146   if (ci->id != this->cur_id) {
00147     strecpy(this->name, ci->filename, lastof(this->name));
00148     this->cur_id = ci->id;
00149     this->downloaded_files++;
00150   }
00151 
00152   this->downloaded_bytes += bytes;
00153   this->SetDirty();
00154 }
00155 
00156 
00158 struct NetworkContentDownloadStatusWindow : public BaseNetworkContentDownloadStatusWindow {
00159 private:
00160   SmallVector<ContentType, 4> receivedTypes;     
00161 
00162 public:
00167   NetworkContentDownloadStatusWindow() : BaseNetworkContentDownloadStatusWindow(&_network_content_download_status_window_desc)
00168   {
00169     this->parent = FindWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST);
00170   }
00171 
00173   ~NetworkContentDownloadStatusWindow()
00174   {
00175     TarScanner::Mode mode = TarScanner::NONE;
00176     for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
00177       switch (*iter) {
00178         case CONTENT_TYPE_AI:
00179         case CONTENT_TYPE_AI_LIBRARY:
00180           /* AI::Rescan calls the scanner. */
00181           break;
00182         case CONTENT_TYPE_GAME:
00183         case CONTENT_TYPE_GAME_LIBRARY:
00184           /* Game::Rescan calls the scanner. */
00185           break;
00186 
00187         case CONTENT_TYPE_BASE_GRAPHICS:
00188         case CONTENT_TYPE_BASE_SOUNDS:
00189         case CONTENT_TYPE_BASE_MUSIC:
00190           mode |= TarScanner::BASESET;
00191           break;
00192 
00193         case CONTENT_TYPE_NEWGRF:
00194           /* ScanNewGRFFiles calls the scanner. */
00195           break;
00196 
00197         case CONTENT_TYPE_SCENARIO:
00198         case CONTENT_TYPE_HEIGHTMAP:
00199           mode |= TarScanner::SCENARIO;
00200           break;
00201 
00202         default:
00203           break;
00204       }
00205     }
00206 
00207     TarScanner::DoScan(mode);
00208 
00209     /* Tell all the backends about what we've downloaded */
00210     for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
00211       switch (*iter) {
00212         case CONTENT_TYPE_AI:
00213         case CONTENT_TYPE_AI_LIBRARY:
00214           AI::Rescan();
00215           break;
00216 
00217         case CONTENT_TYPE_GAME:
00218         case CONTENT_TYPE_GAME_LIBRARY:
00219           Game::Rescan();
00220           break;
00221 
00222         case CONTENT_TYPE_BASE_GRAPHICS:
00223           BaseGraphics::FindSets();
00224           SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
00225           break;
00226 
00227         case CONTENT_TYPE_BASE_SOUNDS:
00228           BaseSounds::FindSets();
00229           SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
00230           break;
00231 
00232         case CONTENT_TYPE_BASE_MUSIC:
00233           BaseMusic::FindSets();
00234           SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
00235           break;
00236 
00237         case CONTENT_TYPE_NEWGRF:
00238           ScanNewGRFFiles(NULL);
00239           break;
00240 
00241         case CONTENT_TYPE_SCENARIO:
00242         case CONTENT_TYPE_HEIGHTMAP:
00243           extern void ScanScenarios();
00244           ScanScenarios();
00245           InvalidateWindowData(WC_SAVELOAD, 0, 0);
00246           break;
00247 
00248         default:
00249           break;
00250       }
00251     }
00252 
00253     /* Always invalidate the download window; tell it we are going to be gone */
00254     InvalidateWindowData(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST, 2);
00255   }
00256 
00257   virtual void OnClick(Point pt, int widget, int click_count)
00258   {
00259     if (widget == WID_NCDS_CANCELOK) {
00260       if (this->downloaded_bytes != this->total_bytes) {
00261         _network_content_client.Close();
00262         delete this;
00263       } else {
00264         /* If downloading succeeded, close the online content window. This will close
00265          * the current window as well. */
00266         DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST);
00267       }
00268     }
00269   }
00270 
00271   virtual void OnDownloadProgress(const ContentInfo *ci, int bytes)
00272   {
00273     BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
00274     this->receivedTypes.Include(ci->type);
00275 
00276     /* When downloading is finished change cancel in ok */
00277     if (this->downloaded_bytes == this->total_bytes) {
00278       this->GetWidget<NWidgetCore>(WID_NCDS_CANCELOK)->widget_data = STR_BUTTON_OK;
00279     }
00280   }
00281 };
00282 
00284 class NetworkContentListWindow : public Window, ContentCallback {
00286   typedef GUIList<const ContentInfo *, StringFilter &> GUIContentList;
00287 
00288   static const uint EDITBOX_MAX_SIZE   =  50; 
00289 
00290   static Listing last_sorting;     
00291   static Filtering last_filtering; 
00292   static GUIContentList::SortFunction * const sorter_funcs[];   
00293   static GUIContentList::FilterFunction * const filter_funcs[]; 
00294   GUIContentList content;      
00295   bool auto_select;            
00296   StringFilter string_filter;  
00297   QueryString filter_editbox;  
00298 
00299   const ContentInfo *selected; 
00300   int list_pos;                
00301   uint filesize_sum;           
00302   Scrollbar *vscroll;          
00303 
00305   void OpenExternalSearch()
00306   {
00307     extern void OpenBrowser(const char *url);
00308 
00309     char url[1024];
00310     const char *last = lastof(url);
00311 
00312     char *pos = strecpy(url, "http://grfsearch.openttd.org/?", last);
00313 
00314     if (this->auto_select) {
00315       pos = strecpy(pos, "do=searchgrfid&q=", last);
00316 
00317       bool first = true;
00318       for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
00319         const ContentInfo *ci = *iter;
00320         if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
00321 
00322         if (!first) pos = strecpy(pos, ",", last);
00323         first = false;
00324 
00325         pos += seprintf(pos, last, "%08X", ci->unique_id);
00326         pos = strecpy(pos, ":", last);
00327         pos = md5sumToString(pos, last, ci->md5sum);
00328       }
00329     } else {
00330       pos = strecpy(pos, "do=searchtext&q=", last);
00331 
00332       /* Escape search term */
00333       for (const char *search = this->filter_editbox.text.buf; *search != '\0'; search++) {
00334         /* Remove quotes */
00335         if (*search == '\'' || *search == '"') continue;
00336 
00337         /* Escape special chars, such as &%,= */
00338         if (*search < 0x30) {
00339           pos += seprintf(pos, last, "%%%02X", *search);
00340         } else if (pos < last) {
00341           *pos = *search;
00342           *++pos = '\0';
00343         }
00344       }
00345     }
00346 
00347     OpenBrowser(url);
00348   }
00349 
00353   static void ExternalSearchDisclaimerCallback(Window *w, bool accepted)
00354   {
00355     if (accepted) {
00356       _accepted_external_search = true;
00357       ((NetworkContentListWindow*)w)->OpenExternalSearch();
00358     }
00359   }
00360 
00365   void BuildContentList()
00366   {
00367     if (!this->content.NeedRebuild()) return;
00368 
00369     /* Create temporary array of games to use for listing */
00370     this->content.Clear();
00371 
00372     bool all_available = true;
00373 
00374     for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
00375       if ((*iter)->state == ContentInfo::DOES_NOT_EXIST) all_available = false;
00376       *this->content.Append() = *iter;
00377     }
00378 
00379     this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select && all_available);
00380 
00381     this->FilterContentList();
00382     this->content.Compact();
00383     this->content.RebuildDone();
00384     this->SortContentList();
00385 
00386     this->vscroll->SetCount(this->content.Length()); // Update the scrollbar
00387     this->ScrollToSelected();
00388   }
00389 
00391   static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b)
00392   {
00393     return strnatcmp((*a)->name, (*b)->name, true); // Sort by name (natural sorting).
00394   }
00395 
00397   static int CDECL TypeSorter(const ContentInfo * const *a, const ContentInfo * const *b)
00398   {
00399     int r = 0;
00400     if ((*a)->type != (*b)->type) {
00401       char a_str[64];
00402       char b_str[64];
00403       GetString(a_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*a)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(a_str));
00404       GetString(b_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*b)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(b_str));
00405       r = strnatcmp(a_str, b_str);
00406     }
00407     if (r == 0) r = NameSorter(a, b);
00408     return r;
00409   }
00410 
00412   static int CDECL StateSorter(const ContentInfo * const *a, const ContentInfo * const *b)
00413   {
00414     int r = (*a)->state - (*b)->state;
00415     if (r == 0) r = TypeSorter(a, b);
00416     return r;
00417   }
00418 
00420   void SortContentList()
00421   {
00422     if (!this->content.Sort()) return;
00423 
00424     for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
00425       if (*iter == this->selected) {
00426         this->list_pos = iter - this->content.Begin();
00427         break;
00428       }
00429     }
00430   }
00431 
00433   static bool CDECL TagNameFilter(const ContentInfo * const *a, StringFilter &filter)
00434   {
00435     filter.ResetState();
00436     for (int i = 0; i < (*a)->tag_count; i++) {
00437       filter.AddLine((*a)->tags[i]);
00438     }
00439     filter.AddLine((*a)->name);
00440     return filter.GetState();
00441   }
00442 
00444   void FilterContentList()
00445   {
00446     if (!this->content.Filter(this->string_filter)) return;
00447 
00448     /* update list position */
00449     for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
00450       if (*iter == this->selected) {
00451         this->list_pos = iter - this->content.Begin();
00452         return;
00453       }
00454     }
00455 
00456     /* previously selected item not in list anymore */
00457     this->selected = NULL;
00458     this->list_pos = 0;
00459   }
00460 
00462   void ScrollToSelected()
00463   {
00464     if (this->selected == NULL) return;
00465 
00466     this->vscroll->ScrollTowards(this->list_pos);
00467   }
00468 
00469 public:
00475   NetworkContentListWindow(WindowDesc *desc, bool select_all) :
00476       Window(desc),
00477       auto_select(select_all),
00478       filter_editbox(EDITBOX_MAX_SIZE),
00479       selected(NULL),
00480       list_pos(0)
00481   {
00482     this->CreateNestedTree();
00483     this->vscroll = this->GetScrollbar(WID_NCL_SCROLLBAR);
00484     this->FinishInitNested(WN_NETWORK_WINDOW_CONTENT_LIST);
00485 
00486     this->GetWidget<NWidgetStacked>(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
00487 
00488     this->querystrings[WID_NCL_FILTER] = &this->filter_editbox;
00489     this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
00490     this->SetFocusedWidget(WID_NCL_FILTER);
00491     this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select);
00492 
00493     _network_content_client.AddCallback(this);
00494     this->content.SetListing(this->last_sorting);
00495     this->content.SetFiltering(this->last_filtering);
00496     this->content.SetSortFuncs(this->sorter_funcs);
00497     this->content.SetFilterFuncs(this->filter_funcs);
00498     this->content.ForceRebuild();
00499     this->FilterContentList();
00500     this->SortContentList();
00501     this->InvalidateData();
00502   }
00503 
00505   ~NetworkContentListWindow()
00506   {
00507     _network_content_client.RemoveCallback(this);
00508   }
00509 
00510   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00511   {
00512     switch (widget) {
00513       case WID_NCL_FILTER_CAPT:
00514         *size = maxdim(*size, GetStringBoundingBox(STR_CONTENT_FILTER_TITLE));
00515         break;
00516 
00517       case WID_NCL_TYPE: {
00518         Dimension d = *size;
00519         for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) {
00520           d = maxdim(d, GetStringBoundingBox(STR_CONTENT_TYPE_BASE_GRAPHICS + i - CONTENT_TYPE_BASE_GRAPHICS));
00521         }
00522         size->width = d.width + WD_MATRIX_RIGHT + WD_MATRIX_LEFT;
00523         break;
00524       }
00525 
00526       case WID_NCL_MATRIX:
00527         resize->height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
00528         size->height = 10 * resize->height;
00529         break;
00530     }
00531   }
00532 
00533 
00534   virtual void DrawWidget(const Rect &r, int widget) const
00535   {
00536     switch (widget) {
00537       case WID_NCL_FILTER_CAPT:
00538         DrawString(r.left, r.right, r.top, STR_CONTENT_FILTER_TITLE, TC_FROMSTRING, SA_RIGHT);
00539         break;
00540 
00541       case WID_NCL_DETAILS:
00542         this->DrawDetails(r);
00543         break;
00544 
00545       case WID_NCL_MATRIX:
00546         this->DrawMatrix(r);
00547         break;
00548     }
00549   }
00550 
00551   virtual void OnPaint()
00552   {
00553     const SortButtonState arrow = this->content.IsDescSortOrder() ? SBS_DOWN : SBS_UP;
00554 
00555     if (this->content.NeedRebuild()) {
00556       this->BuildContentList();
00557     }
00558 
00559     this->DrawWidgets();
00560 
00561     switch (this->content.SortType()) {
00562       case WID_NCL_CHECKBOX - WID_NCL_CHECKBOX: this->DrawSortButtonState(WID_NCL_CHECKBOX, arrow); break;
00563       case WID_NCL_TYPE     - WID_NCL_CHECKBOX: this->DrawSortButtonState(WID_NCL_TYPE,     arrow); break;
00564       case WID_NCL_NAME     - WID_NCL_CHECKBOX: this->DrawSortButtonState(WID_NCL_NAME,     arrow); break;
00565     }
00566   }
00567 
00572   void DrawMatrix(const Rect &r) const
00573   {
00574     const NWidgetBase *nwi_checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
00575     const NWidgetBase *nwi_name = this->GetWidget<NWidgetBase>(WID_NCL_NAME);
00576     const NWidgetBase *nwi_type = this->GetWidget<NWidgetBase>(WID_NCL_TYPE);
00577 
00578 
00579     /* Fill the matrix with the information */
00580     int sprite_y_offset = WD_MATRIX_TOP + (FONT_HEIGHT_NORMAL - 10) / 2;
00581     uint y = r.top;
00582     int cnt = 0;
00583     for (ConstContentIterator iter = this->content.Get(this->vscroll->GetPosition()); iter != this->content.End() && cnt < this->vscroll->GetCapacity(); iter++, cnt++) {
00584       const ContentInfo *ci = *iter;
00585 
00586       if (ci == this->selected) GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 1, PC_GREY);
00587 
00588       SpriteID sprite;
00589       SpriteID pal = PAL_NONE;
00590       switch (ci->state) {
00591         case ContentInfo::UNSELECTED:     sprite = SPR_BOX_EMPTY;   break;
00592         case ContentInfo::SELECTED:       sprite = SPR_BOX_CHECKED; break;
00593         case ContentInfo::AUTOSELECTED:   sprite = SPR_BOX_CHECKED; break;
00594         case ContentInfo::ALREADY_HERE:   sprite = SPR_BLOT; pal = PALETTE_TO_GREEN; break;
00595         case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED;   break;
00596         default: NOT_REACHED();
00597       }
00598       DrawSprite(sprite, pal, nwi_checkbox->pos_x + (pal == PAL_NONE ? 2 : 3), y + sprite_y_offset + (pal == PAL_NONE ? 1 : 0));
00599 
00600       StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS;
00601       DrawString(nwi_type->pos_x, nwi_type->pos_x + nwi_type->current_x - 1, y + WD_MATRIX_TOP, str, TC_BLACK, SA_HOR_CENTER);
00602 
00603       DrawString(nwi_name->pos_x + WD_FRAMERECT_LEFT, nwi_name->pos_x + nwi_name->current_x - WD_FRAMERECT_RIGHT, y + WD_MATRIX_TOP, ci->name, TC_BLACK);
00604       y += this->resize.step_height;
00605     }
00606   }
00607 
00612   void DrawDetails(const Rect &r) const
00613   {
00614     static const int DETAIL_LEFT         =  5; 
00615     static const int DETAIL_RIGHT        =  5; 
00616     static const int DETAIL_TOP          =  5; 
00617 
00618     /* Height for the title banner */
00619     int DETAIL_TITLE_HEIGHT = 5 * FONT_HEIGHT_NORMAL;
00620 
00621     /* Create the nice grayish rectangle at the details top */
00622     GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + DETAIL_TITLE_HEIGHT, PC_DARK_BLUE);
00623     DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + FONT_HEIGHT_NORMAL + WD_INSET_TOP, STR_CONTENT_DETAIL_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
00624 
00625     /* Draw the total download size */
00626     SetDParam(0, this->filesize_sum);
00627     DrawString(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, r.bottom - FONT_HEIGHT_NORMAL - WD_PAR_VSEP_NORMAL, STR_CONTENT_TOTAL_DOWNLOAD_SIZE);
00628 
00629     if (this->selected == NULL) return;
00630 
00631     /* And fill the rest of the details when there's information to place there */
00632     DrawStringMultiLine(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + DETAIL_TITLE_HEIGHT / 2, r.top + DETAIL_TITLE_HEIGHT, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, TC_FROMSTRING, SA_CENTER);
00633 
00634     /* Also show the total download size, so keep some space from the bottom */
00635     const uint max_y = r.bottom - FONT_HEIGHT_NORMAL - WD_PAR_VSEP_WIDE;
00636     int y = r.top + DETAIL_TITLE_HEIGHT + DETAIL_TOP;
00637 
00638     if (this->selected->upgrade) {
00639       SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS);
00640       y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_UPDATE);
00641       y += WD_PAR_VSEP_WIDE;
00642     }
00643 
00644     SetDParamStr(0, this->selected->name);
00645     y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_NAME);
00646 
00647     if (!StrEmpty(this->selected->version)) {
00648       SetDParamStr(0, this->selected->version);
00649       y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_VERSION);
00650     }
00651 
00652     if (!StrEmpty(this->selected->description)) {
00653       SetDParamStr(0, this->selected->description);
00654       y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_DESCRIPTION);
00655     }
00656 
00657     if (!StrEmpty(this->selected->url)) {
00658       SetDParamStr(0, this->selected->url);
00659       y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_URL);
00660     }
00661 
00662     SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS);
00663     y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_TYPE);
00664 
00665     y += WD_PAR_VSEP_WIDE;
00666     SetDParam(0, this->selected->filesize);
00667     y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_FILESIZE);
00668 
00669     if (this->selected->dependency_count != 0) {
00670       /* List dependencies */
00671       char buf[DRAW_STRING_BUFFER] = "";
00672       char *p = buf;
00673       for (uint i = 0; i < this->selected->dependency_count; i++) {
00674         ContentID cid = this->selected->dependencies[i];
00675 
00676         /* Try to find the dependency */
00677         ConstContentIterator iter = _network_content_client.Begin();
00678         for (; iter != _network_content_client.End(); iter++) {
00679           const ContentInfo *ci = *iter;
00680           if (ci->id != cid) continue;
00681 
00682           p += seprintf(p, lastof(buf), p == buf ? "%s" : ", %s", (*iter)->name);
00683           break;
00684         }
00685       }
00686       SetDParamStr(0, buf);
00687       y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_DEPENDENCIES);
00688     }
00689 
00690     if (this->selected->tag_count != 0) {
00691       /* List all tags */
00692       char buf[DRAW_STRING_BUFFER] = "";
00693       char *p = buf;
00694       for (uint i = 0; i < this->selected->tag_count; i++) {
00695         p += seprintf(p, lastof(buf), i == 0 ? "%s" : ", %s", this->selected->tags[i]);
00696       }
00697       SetDParamStr(0, buf);
00698       y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_TAGS);
00699     }
00700 
00701     if (this->selected->IsSelected()) {
00702       /* When selected show all manually selected content that depends on this */
00703       ConstContentVector tree;
00704       _network_content_client.ReverseLookupTreeDependency(tree, this->selected);
00705 
00706       char buf[DRAW_STRING_BUFFER] = "";
00707       char *p = buf;
00708       for (ConstContentIterator iter = tree.Begin(); iter != tree.End(); iter++) {
00709         const ContentInfo *ci = *iter;
00710         if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
00711 
00712         p += seprintf(p, lastof(buf), buf == p ? "%s" : ", %s", ci->name);
00713       }
00714       if (p != buf) {
00715         SetDParamStr(0, buf);
00716         y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF);
00717       }
00718     }
00719   }
00720 
00721   virtual void OnClick(Point pt, int widget, int click_count)
00722   {
00723     if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TFT_END) {
00724       if (this->selected == NULL || this->selected->state != ContentInfo::ALREADY_HERE) return;
00725 
00726       ShowContentTextfileWindow((TextfileType)(widget - WID_NCL_TEXTFILE), this->selected);
00727       return;
00728     }
00729 
00730     switch (widget) {
00731       case WID_NCL_MATRIX: {
00732         uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NCL_MATRIX);
00733         if (id_v >= this->content.Length()) return; // click out of bounds
00734 
00735         this->selected = *this->content.Get(id_v);
00736         this->list_pos = id_v;
00737 
00738         const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
00739         if (click_count > 1 || IsInsideBS(pt.x, checkbox->pos_x, checkbox->current_x)) {
00740           _network_content_client.ToggleSelectedState(this->selected);
00741           this->content.ForceResort();
00742         }
00743 
00744         this->InvalidateData();
00745         break;
00746       }
00747 
00748       case WID_NCL_CHECKBOX:
00749       case WID_NCL_TYPE:
00750       case WID_NCL_NAME:
00751         if (this->content.SortType() == widget - WID_NCL_CHECKBOX) {
00752           this->content.ToggleSortOrder();
00753           if (this->content.Length() > 0) this->list_pos = this->content.Length() - this->list_pos - 1;
00754         } else {
00755           this->content.SetSortType(widget - WID_NCL_CHECKBOX);
00756           this->content.ForceResort();
00757           this->SortContentList();
00758         }
00759         this->ScrollToSelected();
00760         this->InvalidateData();
00761         break;
00762 
00763       case WID_NCL_SELECT_ALL:
00764         _network_content_client.SelectAll();
00765         this->InvalidateData();
00766         break;
00767 
00768       case WID_NCL_SELECT_UPDATE:
00769         _network_content_client.SelectUpgrade();
00770         this->InvalidateData();
00771         break;
00772 
00773       case WID_NCL_UNSELECT:
00774         _network_content_client.UnselectAll();
00775         this->InvalidateData();
00776         break;
00777 
00778       case WID_NCL_CANCEL:
00779         delete this;
00780         break;
00781 
00782       case WID_NCL_OPEN_URL:
00783         if (this->selected != NULL) {
00784           extern void OpenBrowser(const char *url);
00785           OpenBrowser(this->selected->url);
00786         }
00787         break;
00788 
00789       case WID_NCL_DOWNLOAD:
00790         if (BringWindowToFrontById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) == NULL) new NetworkContentDownloadStatusWindow();
00791         break;
00792 
00793       case WID_NCL_SEARCH_EXTERNAL:
00794         if (_accepted_external_search) {
00795           this->OpenExternalSearch();
00796         } else {
00797           ShowQuery(STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER_CAPTION, STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER, this, ExternalSearchDisclaimerCallback);
00798         }
00799         break;
00800     }
00801   }
00802 
00803   virtual EventState OnKeyPress(WChar key, uint16 keycode)
00804   {
00805     switch (keycode) {
00806       case WKC_UP:
00807         /* scroll up by one */
00808         if (this->list_pos > 0) this->list_pos--;
00809         break;
00810       case WKC_DOWN:
00811         /* scroll down by one */
00812         if (this->list_pos < (int)this->content.Length() - 1) this->list_pos++;
00813         break;
00814       case WKC_PAGEUP:
00815         /* scroll up a page */
00816         this->list_pos = (this->list_pos < this->vscroll->GetCapacity()) ? 0 : this->list_pos - this->vscroll->GetCapacity();
00817         break;
00818       case WKC_PAGEDOWN:
00819         /* scroll down a page */
00820         this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->content.Length() - 1);
00821         break;
00822       case WKC_HOME:
00823         /* jump to beginning */
00824         this->list_pos = 0;
00825         break;
00826       case WKC_END:
00827         /* jump to end */
00828         this->list_pos = this->content.Length() - 1;
00829         break;
00830 
00831       case WKC_SPACE:
00832       case WKC_RETURN:
00833         if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) {
00834           if (this->selected != NULL) {
00835             _network_content_client.ToggleSelectedState(this->selected);
00836             this->content.ForceResort();
00837             this->InvalidateData();
00838           }
00839           return ES_HANDLED;
00840         }
00841         /* FALL THROUGH, space is pressed and filter isn't focused. */
00842 
00843       default:
00844         return ES_NOT_HANDLED;
00845     }
00846 
00847     if (this->content.Length() == 0) {
00848       this->list_pos = 0; // above stuff may result in "-1".
00849       return ES_HANDLED;
00850     }
00851 
00852     this->selected = *this->content.Get(this->list_pos);
00853 
00854     /* scroll to the new server if it is outside the current range */
00855     this->ScrollToSelected();
00856 
00857     /* redraw window */
00858     this->InvalidateData();
00859     return ES_HANDLED;
00860   }
00861 
00862   virtual void OnEditboxChanged(int wid)
00863   {
00864     if (wid == WID_NCL_FILTER) {
00865       this->string_filter.SetFilterTerm(this->filter_editbox.text.buf);
00866       this->content.SetFilterState(!this->string_filter.IsEmpty());
00867       this->content.ForceRebuild();
00868       this->InvalidateData();
00869     }
00870   }
00871 
00872   virtual void OnResize()
00873   {
00874     this->vscroll->SetCapacityFromWidget(this, WID_NCL_MATRIX);
00875   }
00876 
00877   virtual void OnReceiveContentInfo(const ContentInfo *rci)
00878   {
00879     if (this->auto_select && !rci->IsSelected()) _network_content_client.ToggleSelectedState(rci);
00880     this->content.ForceRebuild();
00881     this->InvalidateData();
00882   }
00883 
00884   virtual void OnDownloadComplete(ContentID cid)
00885   {
00886     this->content.ForceResort();
00887     this->InvalidateData();
00888   }
00889 
00890   virtual void OnConnect(bool success)
00891   {
00892     if (!success) {
00893       ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_CONNECT, INVALID_STRING_ID, WL_ERROR);
00894       delete this;
00895       return;
00896     }
00897 
00898     this->InvalidateData();
00899   }
00900 
00906   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00907   {
00908     if (!gui_scope) return;
00909     if (this->content.NeedRebuild()) this->BuildContentList();
00910 
00911     /* To sum all the bytes we intend to download */
00912     this->filesize_sum = 0;
00913     bool show_select_all = false;
00914     bool show_select_upgrade = false;
00915     for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
00916       const ContentInfo *ci = *iter;
00917       switch (ci->state) {
00918         case ContentInfo::SELECTED:
00919         case ContentInfo::AUTOSELECTED:
00920           this->filesize_sum += ci->filesize;
00921           break;
00922 
00923         case ContentInfo::UNSELECTED:
00924           show_select_all = true;
00925           show_select_upgrade |= ci->upgrade;
00926           break;
00927 
00928         default:
00929           break;
00930       }
00931     }
00932 
00933     /* If data == 2 then the status window caused this OnInvalidate */
00934     this->SetWidgetDisabledState(WID_NCL_DOWNLOAD, this->filesize_sum == 0 || (FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) != NULL && data != 2));
00935     this->SetWidgetDisabledState(WID_NCL_UNSELECT, this->filesize_sum == 0);
00936     this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all);
00937     this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade);
00938     this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == NULL || StrEmpty(this->selected->url));
00939     for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
00940       this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == NULL || this->selected->state != ContentInfo::ALREADY_HERE || this->selected->GetTextfile(tft) == NULL);
00941     }
00942 
00943     this->GetWidget<NWidgetCore>(WID_NCL_CANCEL)->widget_data = this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL;
00944   }
00945 };
00946 
00947 Listing NetworkContentListWindow::last_sorting = {false, 1};
00948 Filtering NetworkContentListWindow::last_filtering = {false, 0};
00949 
00950 NetworkContentListWindow::GUIContentList::SortFunction * const NetworkContentListWindow::sorter_funcs[] = {
00951   &StateSorter,
00952   &TypeSorter,
00953   &NameSorter,
00954 };
00955 
00956 NetworkContentListWindow::GUIContentList::FilterFunction * const NetworkContentListWindow::filter_funcs[] = {
00957   &TagNameFilter,
00958 };
00959 
00961 static const NWidgetPart _nested_network_content_list_widgets[] = {
00962   NWidget(NWID_HORIZONTAL),
00963     NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
00964     NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE), SetDataTip(STR_CONTENT_TITLE, STR_NULL),
00965     NWidget(WWT_DEFSIZEBOX, COLOUR_LIGHT_BLUE),
00966   EndContainer(),
00967   NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NCL_BACKGROUND),
00968     NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetResize(1, 0),
00969     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(8, 8, 8),
00970       /* Top */
00971       NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_NCL_FILTER_CAPT), SetFill(1, 0), SetResize(1, 0),
00972       NWidget(WWT_EDITBOX, COLOUR_LIGHT_BLUE, WID_NCL_FILTER), SetFill(1, 0), SetResize(1, 0),
00973             SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
00974     EndContainer(),
00975     NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetResize(1, 0),
00976     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(8, 8, 8),
00977       /* Left side. */
00978       NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
00979         NWidget(NWID_HORIZONTAL),
00980           NWidget(NWID_VERTICAL),
00981             NWidget(NWID_HORIZONTAL),
00982               NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_CHECKBOX), SetMinimalSize(13, 1), SetDataTip(STR_EMPTY, STR_NULL),
00983               NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TYPE),
00984                       SetDataTip(STR_CONTENT_TYPE_CAPTION, STR_CONTENT_TYPE_CAPTION_TOOLTIP),
00985               NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_NAME), SetResize(1, 0), SetFill(1, 0),
00986                       SetDataTip(STR_CONTENT_NAME_CAPTION, STR_CONTENT_NAME_CAPTION_TOOLTIP),
00987             EndContainer(),
00988             NWidget(WWT_MATRIX, COLOUR_LIGHT_BLUE, WID_NCL_MATRIX), SetResize(1, 14), SetFill(1, 1), SetScrollbar(WID_NCL_SCROLLBAR), SetMatrixDataTip(1, 0, STR_CONTENT_MATRIX_TOOLTIP),
00989           EndContainer(),
00990           NWidget(NWID_VSCROLLBAR, COLOUR_LIGHT_BLUE, WID_NCL_SCROLLBAR),
00991         EndContainer(),
00992         NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, 8, 0),
00993           NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NCL_SEL_ALL_UPDATE), SetResize(1, 0), SetFill(1, 0),
00994             NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_SELECT_UPDATE), SetResize(1, 0), SetFill(1, 0),
00995                         SetDataTip(STR_CONTENT_SELECT_UPDATES_CAPTION, STR_CONTENT_SELECT_UPDATES_CAPTION_TOOLTIP),
00996             NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_SELECT_ALL), SetResize(1, 0), SetFill(1, 0),
00997                         SetDataTip(STR_CONTENT_SELECT_ALL_CAPTION, STR_CONTENT_SELECT_ALL_CAPTION_TOOLTIP),
00998           EndContainer(),
00999           NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_UNSELECT), SetResize(1, 0), SetFill(1, 0),
01000                         SetDataTip(STR_CONTENT_UNSELECT_ALL_CAPTION, STR_CONTENT_UNSELECT_ALL_CAPTION_TOOLTIP),
01001         EndContainer(),
01002       EndContainer(),
01003       /* Right side. */
01004       NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
01005         NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NCL_DETAILS), SetResize(1, 1), SetFill(1, 1), EndContainer(),
01006         NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, 8, 0),
01007           NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
01008           NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
01009         EndContainer(),
01010         NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, 8, 0),
01011           NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
01012           NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
01013         EndContainer(),
01014       EndContainer(),
01015     EndContainer(),
01016     NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetResize(1, 0),
01017     /* Bottom. */
01018     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(8, 8, 8),
01019       NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_SEARCH_EXTERNAL), SetResize(1, 0), SetFill(1, 0),
01020                     SetDataTip(STR_CONTENT_SEARCH_EXTERNAL, STR_CONTENT_SEARCH_EXTERNAL_TOOLTIP),
01021       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, 8, 0),
01022         NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_CANCEL), SetResize(1, 0), SetFill(1, 0),
01023                       SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
01024         NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_DOWNLOAD), SetResize(1, 0), SetFill(1, 0),
01025                       SetDataTip(STR_CONTENT_DOWNLOAD_CAPTION, STR_CONTENT_DOWNLOAD_CAPTION_TOOLTIP),
01026       EndContainer(),
01027     EndContainer(),
01028     NWidget(NWID_SPACER), SetMinimalSize(0, 2), SetResize(1, 0),
01029     /* Resize button. */
01030     NWidget(NWID_HORIZONTAL),
01031       NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
01032       NWidget(WWT_RESIZEBOX, COLOUR_LIGHT_BLUE),
01033     EndContainer(),
01034   EndContainer(),
01035 };
01036 
01038 static WindowDesc _network_content_list_desc(
01039   WDP_CENTER, "list_content", 630, 460,
01040   WC_NETWORK_WINDOW, WC_NONE,
01041   0,
01042   _nested_network_content_list_widgets, lengthof(_nested_network_content_list_widgets)
01043 );
01044 
01050 void ShowNetworkContentListWindow(ContentVector *cv, ContentType type)
01051 {
01052 #if defined(WITH_ZLIB)
01053   _network_content_client.Clear();
01054   if (cv == NULL) {
01055     _network_content_client.RequestContentList(type);
01056   } else {
01057     _network_content_client.RequestContentList(cv, true);
01058   }
01059 
01060   DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST);
01061   new NetworkContentListWindow(&_network_content_list_desc, cv != NULL);
01062 #else
01063   ShowErrorMessage(STR_CONTENT_NO_ZLIB, STR_CONTENT_NO_ZLIB_SUB, WL_ERROR);
01064   /* Connection failed... clean up the mess */
01065   if (cv != NULL) {
01066     for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) delete *iter;
01067   }
01068 #endif /* WITH_ZLIB */
01069 }
01070 
01071 #endif /* ENABLE_NETWORK */